Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

CommandLine: Allow options specified before the command #927

Closed
bricelam opened this issue Oct 22, 2016 · 2 comments
Closed

CommandLine: Allow options specified before the command #927

bricelam opened this issue Oct 22, 2016 · 2 comments
Labels
area-System.CommandLine OpenBeforeArchiving These issues were open before the repo was archived. For re-open them, file them in the new repo
Milestone

Comments

@bricelam
Copy link
Contributor

I'm using the following definition.

syntax.DefineCommand("build", ref command, "Build.");
syntax.DefineOption("verbose", ref verbose, "Show verbose output.");

If I invoke the command like this, everything works:

$ tool build --verbose

However, if I do it like this, it errors.

$ tool --verbose build
error: unknown command 'build'
@bricelam
Copy link
Contributor Author

Note, you can't allow parameters before the command because these would be ambiguous with the command itself.

@asmichi
Copy link

asmichi commented Aug 20, 2017

+1, it would be great if we can define common options which can appear before the command.

I'd like to add one point. We can only allow options common to all commands. Consider the following definition:

string hash = string.Empty;
syntax.DefineCommand("commit", ref command, Command.Commit, "Commit");
syntax.DefineOption("c", ref hash, true, "Reuse the log message from the specified commit.");

bool count = false;
syntax.DefineCommand("grep", ref command, Command.Grep, "Grep");
syntax.DefineOption("c", ref count, "Show the number of matching lines.");

If we allowed options not common to all commands, tool -c grep commit would be ambiguous because it could be interpreted as both tool grep commit -c ('grep' as a command') and tool commit -c grep ('grep' as an argument of -c).

@pgovind pgovind added the OpenBeforeArchiving These issues were open before the repo was archived. For re-open them, file them in the new repo label Mar 11, 2021
@pgovind pgovind closed this as completed Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.CommandLine OpenBeforeArchiving These issues were open before the repo was archived. For re-open them, file them in the new repo
Projects
None yet
Development

No branches or pull requests

5 participants