[silver:util:cmdargs]

Contents of [silver:util:cmdargs]:

Defined in this grammar:

nonterminal CmdArgs

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 11.

The type of lists of arguments given on the command line

Define a new production (as a cons cell for the CmdArgs list) for each flag given on the command line:

  • For a flag that takes no arguments on the command line, define a production of type (CmdArgs ::= CmdArgs)
  • For a flag that takes a single argument, define a production of type (CmdArgs ::= String CmdArgs)
  • For a flag that takes more arguments, define a prodution of type (CmdArgs ::= [String] CmdArgs)

synthesized attribute cmdRemaining :: [String]

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 17.

The remaining arguments from the commandline after parsing the flags


synthesized attribute cmdError :: Maybe<String>

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 21.

The errors from parsing commandline arguments


nonterminal FlagSpec

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 52.

A specification of a flag for interpretCmdArgs at silver:util:cmdargs/CmdArgs.sv#73.

This uses the annotations-as-record pattern; when a proper record extension is merged, this should use that instead.

The name is the string that should be present in the arguments list in order for this flag to be recognized. In an example -o flag, it would be "-o".

The paramString is a string describing the parameters the flag takes, for use in the help text. In our running example, this might be just("<file>"). For flags that don’t take an argument, this should be nothing().

The help is a string describing the usage of the flag. Typically, this is an English-language string that does not start with a capital letter, nor end with a period. Often the imperative voice is used (e.g. “place the output into ” rather than “the output file is ").

The flagParser is the Flag value used to handle the flag.

Putting these together, the FlagSpec for our example -o flag might look something like:

flagSpec(name="-o", paramString=just("<file>"),
help="place the output into <file>", flagParser=option(outFlag))

abstract production flagSpec   (this::FlagSpec ::= )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 61.

The constructor of FlagSpec values.


function interpretCmdArgs   (CmdArgs ::= flags::[FlagSpec] input::[String] )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 73.

WARNING!
The flag names in the flags parameter MUST start with a hyphen
Parameter flags
A list of FlagSpecs
Parameter input
A list of strings, generally the commandline arguments
Return
The parsed list of arguments

Produce a parsed list of arguments using the given flags from the given input


function flagSpecsToHelpText   (String ::= flagSpecs::[FlagSpec] )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 94.

Formats the –help text for the given FlagSpecs.


abstract production endCmdArgs   (top::CmdArgs ::= remaining::[String] )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 142.

Parameter remaining
Commandline arguments remaining after parsing flags

For defining base, default values for any attributes on CmdArgs


abstract production errorCmdArgs   (top::CmdArgs ::= errmsg::String )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 155.

Parameter errmsg
Error message

Only used when an error is encountered attempting to parse an option. One should always check for .cmdError.isJust BEFORE accessing any other attributes.


nonterminal Flag

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 166.

Flags are a representation of what to do with command line flags/options. It should not be necessary to define any new flags.


abstract production flag   (top::Flag ::= ast::(CmdArgs ::= CmdArgs) )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 180.

Parameter ast
Production for handling this commandline option being given

In the terminology I’ve just made up, a ‘flag’ is a cmd line option with no parameters.


abstract production option   (top::Flag ::= ast::(CmdArgs ::= String CmdArgs) )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 193.

Parameter ast
Production for handling this commandline option being given

In the terminology I’ve just made up, an ‘option’ is a cmd line option with one, single parameter.


abstract production nOptions   (top::Flag ::= n::Integer ast::(CmdArgs ::= [String] CmdArgs) )

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 209.

Parameter n
The number of arguments expected by the flag
Parameter ast
Production for handling this commandline option being given

In the terminology I’ve just made up, ‘nOptions’ is a cmd line option with n parameters.

annotation name :: String

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 55.

(Undocumented.)


annotation paramString :: Maybe<String>

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 56.

(Undocumented.)


annotation help :: String

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 57.

(Undocumented.)


annotation flagParser :: Flag

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 58.

(Undocumented.)


inherited attribute flagInput :: [String]

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 169.

(Undocumented.)


synthesized attribute flagOutput :: [String]

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 170.

(Undocumented.)


inherited attribute flagOriginal :: CmdArgs

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 171.

(Undocumented.)


synthesized attribute flagModified :: CmdArgs

Contained in grammar [silver:util:cmdargs]. Defined at silver/util/cmdargs/CmdArgs.sv line 172.

(Undocumented.)