CommandLineUtils icon indicating copy to clipboard operation
CommandLineUtils copied to clipboard

Make HelpOption discovery work same as for any other option

Open lGSMl opened this issue 5 years ago • 2 comments

At the moment custom command options are searched inside command instance and any parent up the inheritance chain

        public IEnumerable<CommandOption> GetOptions()
        {
            var expr = Options.AsEnumerable();
            var rootNode = this;
            while (rootNode.Parent != null)
            {
                rootNode = rootNode.Parent;
                expr = expr.Concat(rootNode.Options.Where(o => o.Inherited));
            }

            return expr;
        }

But for HelpOption search stops if parent does not have it, even though it may be set further up the chain

 public CommandOption? OptionHelp
        {
            get
            {
                if (_optionHelp != null)
                {
                    return _optionHelp;
                }
                return Parent?.OptionHelp?.Inherited == true
                    ? Parent.OptionHelp
                    : null;
            }
            internal set => _optionHelp = value;
        }

It would be more clear, as for me, if OptionHelp would follow same discovery logic as used for other options.

I have hit some inconvenience working with this when trying to create extension method for CommandLineApplication that would clear duplicate options from subcommands if any.

lGSMl avatar Nov 23 '20 14:11 lGSMl

I would be open to a pull request that implements this. I've marked as help-wanted as I'm not planning to implement on my own, but this seems like a valuable enhancement.

natemcmaster avatar Jan 10 '21 00:01 natemcmaster

https://docs.github.com/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

NhungQuang avatar Oct 13 '21 23:10 NhungQuang

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

github-actions[bot] avatar Oct 14 '22 02:10 github-actions[bot]

Closing due to inactivity. If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.

github-actions[bot] avatar Oct 29 '22 02:10 github-actions[bot]