代码之家  ›  专栏  ›  技术社区  ›  Aakash Goel

指定可选参数的正确语法是什么?

  •  4
  • Aakash Goel  · 技术社区  · 14 年前

    perl mysrc.pl -a=3 -b=4 -c=6
    

    或作为

    perl mysrc.pl -t=15
    

    基本上, (为 t a , b c . 必须至少指定一组值。

    上面的语法怎么说?

    perl mysrc.pl
         [-a=<value of a>]
         [-b=<value of b>]
         [-c=<value of c>]
         [-t=<value of t>]
    

    mysrc.pl ?

    3 回复  |  直到 14 年前
        1
  •  4
  •   DVK    14 年前

    有两种选择:使用“|”作为“或”符号和非方括号进行分组以避免“可选”上下文,或者在多行上列出相互竞争的用法

    perl mysrc.pl {-a=<value of a> -b=<value of b> -c=<value of c>|-t=<value of t>}
    
    perl mysrc.pl UseCaseOneOptions|UseCaseTwoOptions
         UseCaseOneOptions: -a=<value of a> -b=<value of b> -c=<value of c>
         UseCaseTwoOptions: -t=<value of t>
    

    $ cvs --help
      Usage: cvs <command> <per-command-options>
      Please type "cvs command --help" to get help on specific command's options
      Commands are: 
          cvs add
          cvs commmit
          cvs remove
          ...
    
    $ cvs checkout --help
      Usage: cvs checkout [-p] [-A] [-m message] [-M message_file] file_path
          -m message:          check-in comment
          -M file:             read check-in comment from this file
          -p:                  non-sticky checkout. Print the file to STDOUT.
    
    $ cvs diff --help
      Usage: cvs diff [-r VER1] [-r VER2] [-w] file_path
           -w:                 Ignore whitespace
    
        2
  •  3
  •   Jonathan Leffler    14 年前

    我可能会用:

    mycmd [ -t=tval | -a=aval -b=bval -c=cval ] ...
    

    {} '而不是方括号' [] '. 方括号通常表示“可选”。

        3
  •  1
  •   zoul    14 年前

    你是说帮助短信?在这种情况下,您可以执行Subversion所做的操作,例如:

    $ svn help merge
    merge: Apply the differences between two sources to a working copy path.
    usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
           2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]
           3. merge [-c M[,N...] | -r N:M ...] SOURCE[@REV] [WCPATH]