On this page:
Parser
Parser.parse
Parser.print_  help
Parser.flags
Parser.args
Parser.init
Handler
Handler.init
Handler.args
Handler.repeat_  last
Handler.handler
Flag
Flag.flag_  strs
Flag.help
Final  Flag
Multi
Multi.choices
Once  Each
Once  Each.choices
Once  Any
Once  Any.choices
Text
Text.text
Text.placement
Content
Text  Placement
Text  Placement.inline
Text  Placement.after_  options
Text  Placement.after_  notation
make_  builtin_  flags
8.16.0.2
14.6.3 Command Line Parsing Classes🔗ℹ

 import: rhombus/cmdline!class

class

class Parser():

  constructor (

    ~flags: flags :: List.of(Content),

    ~add_builtin: add_builtin :: Any.to_boolean = #true,

    ~args: args :: Handler,

    ~init: init :: Map = {},

    ~who: who :: maybe(error.Who) = #false

  )

 

method

method (p :: Parser).parse(

  ~program: program :: String || Path = cmdline.current_program(),

  ~line: line :: List.of(String) = cmdline.current_command_line()

) :: Map

 

method

method (p :: Parser).print_help(

  ~program: program :: String || Path = cmdline.current_program()

) :: Void

 

property

property (p :: Parser).flags :: List.of(Content)

 

property

property (p :: Parser).args :: Handler

 

property

property (p :: Parser).init :: Map

Represents a parser as normally created by cmdline.parser.

class

class Handler(init :: Map,

              args :: List.of(String),

              repeat_last :: Any.to_boolean,

              handler :: (~any) -> Map):

  nonfinal

Represents a handler, either for a flag or for arguments after all flags. A handler that represents a flag is more specifically an instance of Flag.

The constructor for Handler accepts the same arguments as the default constructor, but checks that args contains valid flags and that handler accepts the number of arguments implied by args.

class

class Flag(flag_strs :: List.of(String),

           help :: maybe(String)):

  nonfinal

  extends Handler

 

class

class FinalFlag():

  extends Flag

 

class

class Multi(choices :: List.of(Flag || Multi))

 

class

class OnceEach(choices :: List.of(Flag || OnceEach))

 

class

class OnceAny(choices :: List.of(Flag || OnceAny))

 

class

class Text(text :: String,

           ~placement: placement :: TextPlacement = #'inline)

 

enumeration

enum Content:

  ~is_a Flag

  ~is_a Multi

  ~is_a OnceEach

  ~is_a OnceAny

  ~is_a Text

 

enumeration

enum TextPlacement:

  inline

  after_options

  after_notation

Flags, flag sets, and help text that can be part of a command-line parser constructed with cmdline.parser or Parser.

The constructor for Flag accepts the same arguments as the default constructor, but checks that flag_strs constaints valid flags.

Returns a list of Content corresponding to flags that are normally added to a command-line parser by default, unless ~no_builtin is used with cmdline.parser or ~add_builtin is supplied as #false to Parser.