首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防止函数在位置上使用除ValueFromRemainingArguments参数以外的参数

防止函数在位置上使用除ValueFromRemainingArguments参数以外的参数
EN

Stack Overflow用户
提问于 2013-10-10 12:52:30
回答 1查看 778关注 0票数 0

我目前正在为Powershell 2.0中的Subversion命令行编写一个包装器。我希望能够尽可能接近命令行的工作方式。因此,例如,我需要"svn“命令:

代码语言:javascript
复制
info: Display information about a local or remote item.
usage: info [TARGET[@REV]...]

  Print information about each TARGET (default: '.').
  TARGET may be either a working-copy path or URL.  If specified, REV
  determines in which revision the target is first looked up.

Valid options:
  -r [--revision] ARG      : ARG (some commands also take ARG1:ARG2 range)
                             A revision argument can be one of:
                                NUMBER       revision number
                                '{' DATE '}' revision at start of the date
                                'HEAD'       latest in repository
                                'BASE'       base rev of item's working copy
                                'COMMITTED'  last commit at or before BASE
                                'PREV'       revision just before COMMITTED
  -R [--recursive]         : descend recursively, same as --depth=infinity
  --depth ARG              : limit operation by depth ARG ('empty', 'files',
                             'immediates', or 'infinity')
  --targets ARG            : pass contents of file ARG as additional args
  --incremental            : give output suitable for concatenation
  --xml                    : output in XML
  --changelist [--cl] ARG  : operate only on members of changelist ARG

Global options:
  --username ARG           : specify a username ARG
  --password ARG           : specify a password ARG
  --no-auth-cache          : do not cache authentication tokens
  --non-interactive        : do no interactive prompting
  --trust-server-cert      : accept SSL server certificates from unknown
                             certificate authorities without prompting (but only
                             with '--non-interactive')
  --config-dir ARG         : read user configuration files from directory ARG
  --config-option ARG      : set user configuration option in the format:
                                 FILE:SECTION:OPTION=[VALUE]
                             For example:
                                 servers:global:http-library=serf

..。要映射到一个函数,如下所示:

代码语言:javascript
复制
function Svn-Info {
    param(
        $revision,
        $depth,
        $targets,
        $incremental,
        $changelist,
        $username,
        $password,
        $no_auth_cache,
        $non_interactive,
        $trust_server_cert,
        $config_dir,
        $config_option,
        [Parameter(Mandatory=$false,ValueFromRemainingArguments=$true)]
        [String[]]
        $targetsAtRev
    )

我想这样称呼它:

代码语言:javascript
复制
Svn-Info "D:\svn\"@25345 "D:\svn\common\"@35922 -username MyUserName -password MyPassword

不幸的是,它试图将前两个参数绑定到$revision和$depth (基本上,前两个尚未绑定的参数)。所以,从本质上说,我能以某种方式阻止参数对任意数量的参数进行位置绑定吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-10 14:06:24

试试看这个param decl:

代码语言:javascript
复制
function Svn-Info {
    [CmdletBinding()]
    param(
        $revision,
        $depth,
        $targets,
        $incremental,
        $changelist,
        $username,
        $password,
        $no_auth_cache,
        $non_interactive,
        $trust_server_cert,
        $config_dir,
        $config_option,
        [Parameter(Mandatory=$false,ValueFromRemainingArguments=$true, Position=0)]
        [String[]]
        $targetsAtRev
    )
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19296269

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档