I have a Perl script that can be called as
perl mysrc.pl -a=3 -b=4 -c=6
or as
perl mysrc.pl -t=15
Basically, (either provide value for t) OR (provide values for all of a, b and c). Atleast one of the groups of values has to be specified.
How do I say the above in syntax?
perl mysrc.pl
     [-a=<value of a>]
     [-b=<value of b>]
     [-c=<value of c>]
     [-t=<value of t>]
would mean that all the parameters are optional, which is not exactly the case. What is the correct way to write the syntax for mysrc.pl?
Two options: either use "|" as an "OR" symbol and non-square brackets for grouping to avoid the "optional" context, or list competing usages on multiple lines
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>
For REALLY complicated sets of options (think CVS), do what CVS does (no xterm at the moment, so below is a crude approximation from memory) - that is, the generic "help" message only lists all possible use cases, and to get help about option sets for each use case, you issue a per-use-case help command.
$ 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
                        I would probably use:
mycmd [ -t=tval | -a=aval -b=bval -c=cval ] ...
where the '...' represents any other options, or the file names, or nothing at all.  And if one or the other set is mandatory, I might use braces '{}' instead of square brackets '[]'.  The square brackets usually indicate 'optional'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With