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 issues when option has separator attribute and when empty value provided... fails #420

Closed
hrnagesh-zz opened this issue Mar 20, 2019 · 3 comments

Comments

@hrnagesh-zz
Copy link

 [Option('b', "BookIds", Required = false, HelpText = "List of Books", Separator = ',')]
        public IEnumerable<string> Bookids { get; set; }

[Option('v', "Verbose", Required = false, Hidden = true, HelpText = "Generate Book details", Default = "Yes")]
        public string All { get; set; }

ProcessBooks -b -v NO


If option has separator attribute and when empty value provided... fails; it considers other argument as its values..

In this case; -b has value -v and NO;

@lobster2012-user
Copy link

my fix

public static IEnumerable<Token> Partition(
            IEnumerable<Token> tokens,
            Func<string, Maybe<TypeDescriptor>> typeLookup)
        {
            return from tseq in tokens.Pairwise(
                (f, s) =>
                        f.IsName() /*&& s.IsValue() fix*/
public static Result<IEnumerable<Token>, Error> ExplodeOptionList(
            Result<IEnumerable<Token>, Error> tokenizerResult,
            Func<string, Maybe<char>> optionSequenceWithSeparatorLookup)
        {
            var tokens = tokenizerResult.SucceededWith().Memorize();

            var replaces = tokens.Select((t, i) =>
                optionSequenceWithSeparatorLookup(t.Text)
                    .MapValueOrDefault(sep => Tuple.Create(i + 1, sep),
                        Tuple.Create(-1, '\0'))).SkipWhile(x => x.Item1 < 0).Memorize();

            var exploded = tokens.Select((t, i) =>
            {
                return replaces.FirstOrDefault(x =>
                {
                    return x.Item1 == i && t.IsValue();//fix
                }).ToMaybe()

@wo-roberts
Copy link

Separately found and fixed this issue and happy to put a PR in if you're happy?

wo-roberts pushed a commit to wo-roberts/commandline that referenced this issue Jul 28, 2020
wo-roberts added a commit to wo-roberts/commandline that referenced this issue Jul 28, 2020
wo-roberts added a commit to wo-roberts/commandline that referenced this issue Jul 28, 2020
wo-roberts added a commit to wo-roberts/commandline that referenced this issue Jul 28, 2020
@rmunn
Copy link
Contributor

rmunn commented Aug 20, 2020

This will be fixed by #684 once it's merged in. (It would also be fixed by #672, but #672 misses a different bug in the same code, so #684's version of the fix is better).

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

4 participants