Skip to content
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

Parsing two list arguments doesn't work #584

Closed
mmierzwa11 opened this issue Jul 8, 2019 · 4 comments
Closed

Parsing two list arguments doesn't work #584

mmierzwa11 opened this issue Jul 8, 2019 · 4 comments

Comments

@mmierzwa11
Copy link

                var argument1 = new Argument<List<string>>
                { Name = "arg1" };
                var argument2 = new Argument<List<string>>
                { Name = "arg2" };
                var command = new Command("do-stuff");
                command.AddArgument(argument1);
                command.AddArgument(argument2);
                command.Handler = CommandHandler.Create( (List<string> arg1, List<string> arg2) =>
                {
                    //TODO: Implement command handler
                });
                var builder = new CommandLineBuilder()
                    .AddCommand(command)
                    .UseDefaults();

                Parser parser = builder.Build();

Invoking following command definition as "do-stuff args1 args2" results in arg1 with both values and arg2 as null in CommandHandler - I expected args1 in arg1 list and args2 in arg2 list, is there any option to specify that spaces are delimiters for arguments and let say commas for items in list so invoking "do-stuff args1a,args1b args2" result in arg1 list with two items (args1a, args1b) and arg2 list with only one item (args2).

@jonsequitur
Copy link
Contributor

What you're seeing is the default behavior because argument1 has no upper limit specified for its arity. You can see an example of how this works here:

public void Multiple_arguments_can_differ_by_arity()
{
var command = new Command("the-command")
{
new Argument<string>
{
Arity = new ArgumentArity(3, 3),
Name = "several"
},
new Argument<string>
{
Arity = ArgumentArity.ZeroOrMore,
Name = "one"
}
};
var result = command.Parse("1 2 3 4");
var several = result.CommandResult
.GetArgumentValueOrDefault<IEnumerable<string>>("several");
var one = result.CommandResult
.GetArgumentValueOrDefault<IEnumerable<string>>("one");
several.Should()
.BeEquivalentSequenceTo("1", "2", "3");
one.Should()
.BeEquivalentSequenceTo("4");
}

The comma approach is interesting. Do you have examples of command line interfaces using this convention in the way you're describing?

Related: #37

@amis92
Copy link

amis92 commented Jul 17, 2019

I can't say anything about existing tools, but PowerShell uses commas for lists, and CLI-tool framework PowerArgs uses this notation as well.

@mmierzwa11
Copy link
Author

I don't really know/remember any wide used tools with such approach, but in past I used to use argparse lib for python, which has such concept.

@jonsequitur
Copy link
Contributor

I'm closing this as a duplicate of #37. Please feel free to reopen if there are details I'm missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants