Skip to content

Options Parser #118

Description

@mollymorphic

Higgs allows users to pass arguments to scripts by including them after "--", like so:

./higgs script.js -- foo bar

However, this just provides an array of strings (in this case ["foo", "bar"]). Higgs should include a library that makes it easy for scripts to declare what arguments and options they take, which ones are required, etc. The library should then take an argument array like:

["plain arg", "second plain arg", "--opt", "value", "--secondopt", "value", "value"]

and produce an array of the arguments like:

["plain arg", "second plain arg"]

as well as an opts object like

{
    "opt" : "value",
    "secondopt" : ["value", "value"]
}

If all required args/options are not present an error should be thrown and/or a message displayed and the program exited.

A possible enhancement would be to take an optional description of what each option does, and use this to construct a "usage" message to display when no/incorrect args/opts are passed or the "-help" option is encountered.

Another possible enhancement would be to take an optional type for each arg/opt and then convert the argument/opt value to that type before passing it along to the library user, or an optional "converter function" to be applied to the opt/arg before passing it on to the library user.

Feedback for possible extra features, ideas for what the API should look like, and any other general thoughts are very welcome (^_^).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions