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

HelpVerbOptionAttribute broken #138

Closed
CrescentFresh opened this issue Oct 2, 2014 · 5 comments
Closed

HelpVerbOptionAttribute broken #138

CrescentFresh opened this issue Oct 2, 2014 · 5 comments

Comments

@CrescentFresh
Copy link

Piecing together [HelpVerbOption] usage, the below example from the wiki doesn't render anything.

CommandLine 1.9.71 via nuget.

Repro:

class Options
{
    public Options()
    {
        // Since we create this instance the parser will not overwrite it
        CommitVerb = new CommitSubOptions();
    }

    [CommandLine.VerbOption("commit", HelpText = "Record changes to the repository.")]
    public CommitSubOptions CommitVerb { get; set; }

    [CommandLine.HelpVerbOption]
    public string GetUsage(string verb)
    {
        return "this never appears";
    }
}

class CommitSubOptions
{
    [CommandLine.Option('a', "all", HelpText = "Tell the command to automatically stage files.")]
    public bool All { get; set; }
    // Remainder omitted
}

internal class Program
{
    private static void Main(string[] args)
    {
        var options = new Options();
        args = "help commit".Split();
        CommandLine.Parser.Default.ParseArguments(args, options);
        Console.ReadLine();
    }
}
@JMerrill
Copy link

JMerrill commented Oct 3, 2014

ParseArguments() has an overload that takes an onVerbCommand delegate as the third parameter. Without that, there isn't a way AFAIK to find out what the verb is, making that code a poor example of the use of verbs. Though it seems unrelated, my code has that third parameter, and the method with HelpVerbOptionAttribute gets called.

However, in your example ("help commit"), GetUsage is called with "help" as the verb, without there being any info about what was passed after that ("commit"); I have not found a way to get the mechanism to display help for the options specific to [in your example] "commit", or even to find out that there's anything passed after "help".

I tried referencing an IParserState-returning property in GetUsage(), thinking that it might have information about extra values on the commandline -- but it's null. Is there any way to see what (if anything) was passed after "help" on the command line in this case? Is there any way to get the HelpText.AutoBuild mechanism to show the help about a particular verb? (Does perhaps each XxxSubOptions also need a GetUsage? There's no mention of that in the discussion of verbs.)

@thesolution
Copy link

This issue was corrected in pull request #74 but was not accepted. So the options are fork or use something like ManyConsole if you need verbs.

@element533
Copy link

I would like to see this fix, if possible.

@nemec
Copy link
Collaborator

nemec commented Mar 9, 2015

@cosmo0's fork accepts pull requests. Unfortunately the dev here disappeared.

@gsscoder
Copy link
Owner

@CrescentFresh, @JMerrill, @spadfield please check if https://github.com/gsscoder/commandline/wiki/Verb-Commands this solves the problem. Since I was away for a while maybe that when you posted wiki was outdated. As for all the rest of the wiki this is about stable.

Latest days (in moment of writing this post) work is proceeded on 2.0 pre-rel, making it more usable (it was really a preview before these times, I know...).

Some info (for the moment not a full wiki) for 2.0 pre-rel can be found here: https://github.com/gsscoder/commandline/wiki/Latest-Version. I've recently added a section about verb commands.

If this not help, please ping; I'm back and I'm here to help!

cc/ @nemec @mizipzor @gimmemoore

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

6 participants