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

Tuple options don't parse the same as strings #132

Closed
dwarburt opened this issue Aug 6, 2018 · 1 comment
Closed

Tuple options don't parse the same as strings #132

dwarburt opened this issue Aug 6, 2018 · 1 comment
Assignees
Milestone

Comments

@dwarburt
Copy link

dwarburt commented Aug 6, 2018

Describe the bug
A value for a string option can be specified on the command line with a space separating the option name and value. If it's a tuple, this will cause an "Unrecognized command or argument" instead.

To Reproduce
Steps to reproduce the behavior:

  1. Using this version of the library: 2.2.5
  2. Run this code:
using System;
using McMaster.Extensions.CommandLineUtils;
namespace tuple_parse
{
    class Program
    {
        static void Main(string[] args)
        {
            CommandLineApplication.Execute<Program>(args);
        }
        [Option("-s|--string <value>")]
        public String StringOpt {get;}

        [Option("-t|--tuple <tuple>")]
        public (bool hasValue, string value) TupleOpt {get;}
        int OnExecute(CommandLineApplication app, IConsole console)
        {
            Console.WriteLine($"string: {StringOpt}, tuple: {TupleOpt.value}");
            return 1;
        }
    }
}

  1. With these arguments --string 1 --tuple 2
  2. See error: Unrecognized command or argument '2'

Expected behavior
A tuple option should be recognized when the value follows a space.

Screenshots

image

@natemcmaster
Copy link
Owner

Tuples map to SingleOrNoValue. In this example, --tuple 2 is ambiguous. This is a limitation of parser, and I haven't found a good solution. What is "2"? The value of --tuple? A subcommand? An argument on the command object? While there may be a set of programs for which we could infer that "2" is the option value, there is a much larger set in which this usage is ambiguous. So, for now you must use --tuple=2 for ValueTuple<bool, string> properties.

FYI this is one of the edge cases I've documented in a doc I started drafting last week. I'll leave this open till this doc is ready.

https://raw.githubusercontent.com/natemcmaster/CommandLineUtils/75de7e3e9d74139f5209d61decde1c78ec6e1237/docs/docs/options-and-args.md

@natemcmaster natemcmaster added this to the 2.3.0 milestone Sep 25, 2018
@natemcmaster natemcmaster self-assigned this Oct 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants