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

CommandLine: Nested commands #923

Closed
bricelam opened this issue Oct 22, 2016 · 1 comment
Closed

CommandLine: Nested commands #923

bricelam opened this issue Oct 22, 2016 · 1 comment
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

bricelam commented Oct 22, 2016

There appears to be no way to implement subcommands using System.CommandLine. For example:

git remote
git remote add <name> <url>
git remote rename <old> <new>

My intuition was to try doing this:

syntax.DefineCommand("remote", ref command, "Lists remotes.");

syntax.DefineCommand("remote add", ref command, "Adds a remote.");
syntax.DefineParameter("name", ref name, "The name.");
syntax.DefineParameter("url", ref url, "The url.");

syntax.DefineCommand("remote rename", ref command, "Renames a remote.");
syntax.DefineParameter("old", ref oldName, "The old name.");
syntax.DefineParameter("new", ref name, "The new name.");

Unfortunately, it throws:

System.ArgumentException: Name 'remote add' cannot be used for a command.
Parameter name: name
   at System.CommandLine.ArgumentSyntax.DefineCommand[T](String name, T value)
   at System.CommandLine.ArgumentSyntax.DefineCommand[T](String name, T& command, T value, String help)
   at System.CommandLine.ArgumentSyntax.DefineCommand(String name, String& value, String help)
   at System.CommandLine.ArgumentSyntax.Parse(IEnumerable`1 arguments, Action`1 defineAction)
@bricelam
Copy link
Contributor Author

Note, parameters couldn't be allowed on parent commands since these would become ambiguous with child command.

@ahsonkhan ahsonkhan added this to the Future milestone Apr 6, 2017
@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

4 participants