[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 13.

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)

This shouldn’t have inherited attributes, but can’t be data because of how we abuse forwarding for defining flags.


synthesized attribute cmdRemaining :: [String]

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

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 23.

The errors from parsing commandline arguments


data 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#68.

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))

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

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

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 89.

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 137.

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 150.

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 161.

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 175.

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 188.

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 204.

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.

abstract production flagSpec   (FlagSpec ::= )

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

(Undocumented.)


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 164.

(Undocumented.)


synthesized attribute flagOutput :: [String]

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

(Undocumented.)


inherited attribute flagOriginal :: CmdArgs

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

(Undocumented.)


synthesized attribute flagModified :: CmdArgs

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

(Undocumented.)