变量准则
创建命令或数据源类型时,您必须了解 OnCommand Workflow Automation ( WFA )中 PowerShell 和 Perl 变量的准则。
PowerShell 变量
| 准则 | 示例 | 
|---|---|
对于脚本输入参数: 
  | 
` $VolumeName` ` $AutoDeleteOptions` ` $size`  | 
对于脚本内部变量: 
  | 
` $newVolume` ` $qtreeName` ` $time`  | 
对于功能: 
  | 
  | 
变量名称不区分大小写。但是,为了提高可读性,不应对同一名称使用不同的大写。  | 
` $variable` 与 ` $Variable 相同。`  | 
变量名称应使用纯英文,并且应与脚本的功能相关。  | 
请使用 ` $name` ,而不是 ` $a`  | 
显式声明每个变量的数据类型。  | 
字符串名称 大小  | 
请勿使用特殊字符(!@ # & % , . )和空格。  | 
无  | 
请勿使用 PowerShell 保留的关键字。  | 
无  | 
通过先放置必填参数,然后再放置可选参数来对输入参数进行分组。  | 
param( [parameter(Mandatory=$true)] [string]$Type, [parameter(Mandatory=$true)] [string]$Ip, [parameter(Mandatory=$false)] [string]$VolumeName )  | 
使用 ` HelpMessage` 标注和有意义的帮助消息对所有输入变量进行注释。  | 
[parameter(Mandatory=$false,HelpMessage="LUN to map")] [string]$LUNName  | 
请勿使用 "`Filer` " 作为变量名称;请改用 "`Array` " 。  | 
无  | 
如果参数获得枚举值,请使用 ` ValidateSet` 标注。此操作会自动转换为参数的 Enum 数据类型。  | 
[parameter(Mandatory=$false,HelpMessage="Volume state")]
[ValidateSet("online","offline","restricted")]
[string]$State
 | 
向以 "` _capacity` " 结尾的参数添加别名,以指示此参数的容量类型。  | 
"`Create Volume` " 命令使用别名,如下所示: [parameter(Mandatory=$false,HelpMessage="Volume increment size in MB")]
[Alias("AutosizeIncrementSize_Capacity")]
[int]$AutosizeIncrementSize
 | 
向以 "` 密码` " 结尾的参数添加别名,以指示此参数的密码类型。  | 
param (
  [parameter(Mandatory=$false, HelpMessage="In order to create an Active Directory machine account for the CIFS server or setup CIFS service for Storage Virtual Machine, you must supply the password of a Windows account with sufficient privileges")]  [Alias("Pwd_Password")]  [string]$ADAdminPassword
)
 | 
Perl 变量
| 准则 | 示例 | 
|---|---|
对于脚本输入参数: 
  | 
` $VolumeName` ` $AutoDeleteOptions` ` $size`  | 
不要使用脚本内部变量的缩写。  | 
` $new_volume` ` $qtree_name` ` $time`  | 
请勿使用缩写词来表示函数。  | 
  | 
变量名称区分大小写。为了提高可读性,不应对同一名称使用不同的大写。  | 
` $variable` 与 ` $Variable 不同。`  | 
变量名称应使用纯英文,并且应与脚本的功能相关。  | 
请使用 ` $name` ,而不是 ` $a`  | 
首先放置必需参数,然后再放置可选参数,对输入参数进行分组。  | 
无  | 
在 GetOptions 函数中,显式声明输入参数的每个变量的数据类型。  | 
GetOptions( "Name=s"=>\$Name, "Size=i"=>\$Size )  | 
请勿使用 "`Filer` " 作为变量名称;请改用 "`Array` " 。  | 
无  | 
Perl 不包含枚举值的 ` ValidateSet` 标注。如果参数获得枚举值,请使用显式 "`if` " 语句。  | 
if (defined$SpaceGuarantee&&!($SpaceGuaranteeeq'none'  | 
$SpaceGuaranteeeq'volume'  | 
|
$SpaceGuaranteeeq'file')) { die'Illegal SpaceGuarantee argument: \''.$SpaceGuarantee.'\''; } ----  | 
|
所有 Perl WFA 命令都必须使用   | 
use strict; # the above is equivalent to use strictvars; use strictsubs; use strictrefs;  | 
所有 Perl WFA 命令都必须使用以下 Perl 模块: 
  | 
use Getopt::Long; use NaServer; use WFAUtil;  |