Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.48k stars 60 forks source link

Anonymous options #9

Closed Tyrrrz closed 5 years ago

Tyrrrz commented 5 years ago

...aka options that don't have a name.

Allow doing something like app command <option> or even app command <option> subcommand. Currently this is not possible because <option> will be parsed as part of the command name.

Also, what do we do in case of conflicts? E.g. app command <option> where <option> matches the name of one of the subcommands.

Some inspiration can be drawn here: http://docopt.org/

imscottirl commented 5 years ago

I specifically need this option for the Warpdrive SDK so I'm going to implement it.

Tyrrrz commented 5 years ago

The main challenge with this is that, unlike options, command arguments are ambiguous, i.e. given myapp foo bar, you can't tell whether bar is an argument or part of a longer command name foo bar.

This can be solved by not discerning between command name/arguments at the time of parsing, instead producing something like IReadOnlyList<string> Route which contains all arguments leading up to the first option. And then determine which part belongs to command name and which part to arguments at a later stage.

imscottirl commented 5 years ago

I was thinking of something like adding an overload that specified it's relative order. <exe> <command> <option1> <option2> <option3> And make the options have attributes that have 1, 2, and 3, etc..

Tyrrrz commented 5 years ago

Given a command line exe foo bar lorem ipsum --apples oranges can you tell where command name ends and anonymous options start? :)

Tyrrrz commented 5 years ago

Closed in favor of more descriptive #26