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

Question - Custom HelpHooks #40

Closed
Geraint87 opened this issue Jan 12, 2014 · 3 comments
Closed

Question - Custom HelpHooks #40

Geraint87 opened this issue Jan 12, 2014 · 3 comments

Comments

@Geraint87
Copy link

How would I go about creating a custom help hook, that opened up a URL instead of writing to console, for example?

I created UrlHelpHook : HelpHook and overrode the AfterCancel event, but whichever one I call, it always performs both the HelpHook AfterCancel and the UrlHelpHook AfterCancel.

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Parameter)]
    public class UrlHelpHookAttribute : HelpHook
    {
        private string helpUrl;

        public UrlHelpHookAttribute(string url)
            :base()
        {
            this.helpUrl = Path.GetFullPath(url);

            if (!File.Exists(this.helpUrl))
            {
                throw new ValidationArgException("File not found - " + url, new FileNotFoundException());
            }
        }

        public override void AfterCancel(HookContext context)
        {
            if (WriteHelp == false) return;

            Console.WriteLine(@"Launching default browser to display HTML ...");
            Process.Start(this.helpUrl);
        }
    }
@adamabdelhamed
Copy link
Owner

Is it possible that you have 2 help hooks registered in your argument definition? Without looking at your complete code I can't imagine how this can happen. Your override code is not calling the base method so that base code should not execute.

If you share your complete code I can take a look.

Thanks,
Adam

@Geraint87
Copy link
Author

Thanks for getting back to me so quickly!

Yes, I did have two HelpHooks registered. I was trying both alongside each other to start with, with the Url one omitted from the usage:

        #region Global Options

        [HelpHook]
        [ArgShortcut("?")]
        public bool Help { get; set; }

        [ArgShortcut("~")]
        [OmitFromUsageDocs]
        [UrlHelpHook("myhelpurl.html")]
        public bool HelpUrl { get; set; }

        #endregion Global Options

So you can only have one?

At the moment, I have 3 action methods, with 4-6 arguments each - so the help text is getting too long for the console window.

Is there a way I could customise the usage, so that:

  1. At the top level (i.e. with no action specified, so myapplication -?) it just listed the actions and global options without recursively drilling down into each argument of each action?
  2. Have the context update itself so that myapplication myaction -? only returned the help usage for that action? (I see you've added SpecifiedAction to ArgUsageOptions, but it still isn't there in the AfterCancel of HelpHook.

If it would be possible to do this, I wouldn't need UrlHelpHook at all really!

Thanks!

@adamabdelhamed
Copy link
Owner

Fixed in 2.5.0.0

[HelpHook] will now automatically know if there was an action specified on the command line and will only show specific help for that action in that case.

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