Argon: an alternative parser for command-line arguments
Victor Porton
porton at narod.ru
Sun Jan 27 06:29:44 UTC 2019
On Wednesday, 9 March 2016 at 18:56:10 UTC, Markus Laker wrote:
> To support git-style syntax while using Argon, I'd do this:
>
> 1. Find the (possibly empty) initial sequence of tokens that
> start with a dash. Pass them to an Argon-derived class which
> we'll call `Stem', which parses them.
>
> 2. If no more tokens exist (as in "my-command --help"), do what
> we can with the options we've seen, and then exit.
>
> 3. Otherwise, the next token must be a subcommand name: we've
> seen something "my-command --verbose display-widgets
> --paginate".
> Use that token to select a leaf class, also derived from
> Argon. There's one leaf class per subcommand.
>
> 4. Pass the remaining tokens (in this example, just
> "--paginate") to the selected leaf pass for parsing. Also pass
> a reference to Stem, so that the leaf code can use any options
> garnered by Stem.
It is a wrong way, because switches may have arguments (not
starting with a dash).
I am now considering to write a new object-oriented command line
parser from scratch because it is sometimes easier to write new
code than to understand other's one.
> It shouldn't be hard to write some reusable code to do this, if
> it were a common requirement.
More information about the Digitalmars-d-announce
mailing list