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

Support for option groups #92

Open
Tyrrrz opened this issue Feb 8, 2021 · 4 comments
Open

Support for option groups #92

Tyrrrz opened this issue Feb 8, 2021 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Tyrrrz
Copy link
Owner

Tyrrrz commented Feb 8, 2021

Related to #6

Curious what are the potential use cases people have for this?
An obvious one is making two options mutually exclusive, but maybe there is something else?

@Tyrrrz Tyrrrz added the enhancement New feature or request label Feb 8, 2021
@Tyrrrz Tyrrrz changed the title Reimplement option groups Implement option groups Mar 22, 2021
@Tyrrrz Tyrrrz changed the title Implement option groups Support for option groups Feb 6, 2023
@Tyrrrz Tyrrrz added the help wanted Extra attention is needed label Aug 7, 2023
@sandreas
Copy link

sandreas commented Dec 23, 2024

I would use this possibility to group the documentation / usage output for better understanding... Let's take my project tone for an example.

  • There are global options / parameters like --help, --verbose, --debug or --force
  • There are query options like --query, --order-by, --limit
  • There are template options like --include-property, --exclude-property, --format, etc.
  • There are topic-prefix groups (Logging: --log-{level,file}, Metadata: --meta-{artist,album,title,sort-album,...})

Usually, I would create a usage output in alphabetical order, but it would be a huge usability improvement to have them grouped depending on the purpose.

@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Dec 26, 2024

@sandreas in your use case, you're primarily looking after grouping inside the help text, right? Are you also interested in how it affects parsing, i.e. not being able to use both --query and --help together? Or is that not important?

@sandreas
Copy link

sandreas commented Dec 26, 2024

in your use case, you're primarily looking after grouping inside the help text, right?

Correct.

Example

[Command]
[GroupDescription("direction", "Options to choose the direction")]
[GroupDescription("meta", "Options to modify metadata")]
public class MetaCommand : ICommand
{
    [Group("direction")]
    [CommandOption("left")]
    public string Left { get; init; } = "Hello";

    [Group("direction")]
    [CommandOption("right")]
    public string Right { get; init; } = "world";

    [Group("meta")]
    [CommandOption("meta-album")]
    public string MetaAlbum { get; init; } = "";

    [Group("meta")]
    [CommandOption("meta-artist")]
    public string MetaArtist { get; init; } = "";

    public ValueTask ExecuteAsync(IConsole console)
    {
        console.Output.Write(Left);
        console.Output.Write(' ');
        console.Output.Write(Right);

        return default;
    }
}

Are you also interested in how it affects parsing, i.e. not being able to use both --query and --help together? Or is that not important?

While that would be an interesting thing to have, in my use case this would not have much benefit, because --help is a context specific, globally available boolean option. tone --help, tone dump --help and tone tag --help would show completely different output, while tone tag --query would not make any sense (--query is only available in thedump subcommand).

Maybe this is just a problem of terminology. In my head groups are things that somehow belong together logically, while Constraints would be things that restrict others, are mutually exclusive or depend on each other. Constraints would be much more complex to configure, I doubt that this would be convenient to do without prepared templates (e.g. for --help the [HelpOptionConstraint] combining [GlobalConstraint] and [ContextSensitiveConstraint]). Most importantly, restricting the usage of parameters may lead to unexpected consequences - what if I configured a long command and now want to see the --help page again, would it be good to restrict the --help parameter to be mutually exclusive or more like a pain not to be able to add it afterwards to look something up? I'm not sure...

While groups sound interesting, I probably wouldn't use constraints too much, but maybe I'm the wrong person to talk about these :-)

@Tyrrrz
Copy link
Owner Author

Tyrrrz commented Dec 27, 2024

The original idea behind groups did envision some form of constraints, so I'm gathering feedback whether this is what users expect to find behind that functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants