Skip to content

HelpVerbOptionAttribute broken #138

Closed
@CrescentFresh

Description

@CrescentFresh

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();
    }
}

Activity

JMerrill

JMerrill commented on Oct 3, 2014

@JMerrill

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

thesolution commented on Jan 18, 2015

@thesolution

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

element533 commented on Mar 9, 2015

@element533

I would like to see this fix, if possible.

nemec

nemec commented on Mar 9, 2015

@nemec
Collaborator

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

gsscoder

gsscoder commented on Jun 19, 2015

@gsscoder
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nemec@JMerrill@gsscoder@thesolution@element533

        Issue actions

          HelpVerbOptionAttribute broken · Issue #138 · gsscoder/commandline