-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for default verb? #174
Comments
Furthermore, is it possible to have global options while still having a verb? |
Thanks for the quick reply, @nemec. What about a simple Update: Actually, quite a nice solution that already works is simply inheriting from a |
I'm currently trying to come up with a workaround for this, but I can't get the |
Update: it seems I have to specify at least two options types to |
You're right - it is not obvious that one generic argument is interpreted as an Options class but multiple are considered Verbs. |
Just to clarify, is there a workaround by using GlobalOptions? |
I try to find a workaround. I use solution like this and it seems to work. [Verb("add", HelpText = "Add file contents to the index.")]
class AddOptions
{ //normal options here
}
[Verb("commit", HelpText = "Record changes to the repository.")]
class CommitOptions
{ //normal options here
}
class CloneOptions
{ //normal options here
}
class Program
{
static void Main(string[] args)
{
Parser parser = new Parser(o =>
{
o.HelpWriter = null;
});
var result = parser.ParseArguments<AddOptions, CommitOptions>(args);
if ((result is NotParsed<object>) &&
((NotParsed<object>)result).Errors.Any(o => o.Tag == ErrorType.NoVerbSelectedError || o.Tag == ErrorType.BadVerbSelectedError))
{
parser.ParseArguments<CloneOptions>(args)
.WithParsed<CloneOptions>(opts => Console.WriteLine(opts))
.WithNotParsed(errs => Console.WriteLine(errs.First().Tag));
}
else
{
result
.WithParsed<AddOptions>(opts => Console.WriteLine(opts))
.WithParsed<CommitOptions>(opts => Console.WriteLine(opts))
.WithNotParsed(errs => Console.WriteLine(errs.First().Tag));
}
}
} |
I have some legacy options (without a verb) and need to add some verbs. I came up with a similar workaround like @tkouba. The problem with such an approach is that help texts are no longer automatically generated. So built-in support for default verbs would be much appreciated. The CLAP library (https://github.com/adrianaisemberg/CLAP) seems to support default verbs, but I'm hesitating to move to that library, because it does not look like it's still actively maintained. Is supporting default verbs on the roadmap for this library? |
V2.8 support default verb |
Monday Oct 16, 2017 at 17:20 GMT
Originally opened as gsscoder/commandline#494
Is there any support for some sort of "default" verb? That is, a verb that gets executed when no verb is actually specified. Perhaps an existing verb can be marked as default, even?
The text was updated successfully, but these errors were encountered: