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

Verb option help is not rendering Enum value options #246

Open
kensykora opened this issue Oct 1, 2015 · 4 comments
Open

Verb option help is not rendering Enum value options #246

kensykora opened this issue Oct 1, 2015 · 4 comments

Comments

@kensykora
Copy link

When I create a verb object with a verb that has an enum value option, the help for the verb is not rendering. See example here: https://gist.github.com/kensykora/f486cdf239a823390409

Basically, any enum that's a positional parameter doesn't show up in autobuild help. It'd also be nice if the enum displayed it's string value rather than the int value, maybe even used the System.ComponentModel.DescriptionAttribute option?

@gsscoder
Copy link
Owner

gsscoder commented Oct 5, 2015

📎 Please read: #250. Thanks for collaboration and patience! 😅
Giacomo
P.S.: valid only for me, if a main contrib. is available he's obviously free to support devs/users of the project.

@blakecausey
Copy link

This error appears to be in the TryParseHelpVerb method where the verb is fetched as the first item of the args parameter but for "help" the verb should be the second item. e.g. "myapp help commit" where "commit" is the verb.

The following line shows where it fetches the first item of args.

var verb = args.FirstOrDefault();

To prove my point, the following "if" statement looks for "help" in args[0] and will return if it does not find it as shown below:

if (string.Compare(args[0], helpInfo.Right.LongName, GetStringComparison(_settings)) == 0)

Below is the complete method.

private bool TryParseHelpVerb(string[] args, object options, Pair<MethodInfo, HelpVerbOptionAttribute> helpInfo, OptionMap optionMap)
{
    var helpWriter = _settings.HelpWriter;
    if (helpInfo != null && helpWriter != null)
    {
        if (string.Compare(args[0], helpInfo.Right.LongName, GetStringComparison(_settings)) == 0)
        {
            // User explicitly requested help
            var verb = args.FirstOrDefault();
            if (verb != null)
            {
                var verbOption = optionMap[verb];
                if (verbOption != null)
                {
                    if (verbOption.GetValue(options) == null)
                    {
                        // We need to create an instance also to render help
                        verbOption.CreateInstance(options);
                    }
                }
            }

            DisplayHelpVerbText(options, helpInfo, verb);
            return true;
        }
    }

    return false;
}

I'm unable to get the time to test my theory or even come up with a fix but most likely I would do something like:

var verb = args.Skip(1).FirstOrDefault();

@DanHarman
Copy link

Enum parsing with verbs as positional arguments is also currently case sensitive when I don't believe it should be.

@jkodroff
Copy link

@DanHarman I agree. See: #326

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

5 participants