Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.48k stars 60 forks source link

Options groups #6

Closed Tyrrrz closed 5 years ago

Tyrrrz commented 5 years ago

Specify a group on an option. Options from the same group can/cannot be used simultaneously.

Tyrrrz commented 5 years ago

Implemented as an attribute property GroupName. When scanning input, the group is recognized from the first option. Options from a different group are ignored.

Tyrrrz commented 5 years ago

Removed this feature. Need to rethink how it should be implemented based on actual use cases.

strange-v commented 3 years ago

Would be cool to have this feature implemented. Currently, I use two not required options and custom validation, but it isn't the right way.

CartBlanche commented 1 year ago

We currently have long list of commands (thanks for publishing the alphabetised feature, so much easier now :) ) and it would be nice to shorten the list so that commands that have the same beginning are grouped under that top level command. eg. as per the attached screenshot we currently have...

  device info       Get the device info
  device mac        Read the ESP32's MAC address
  device name       Get the name of the Meadow
  device provision  Registers and prepares connected device for use with Meadow Cloud

I would love a way for this list to be compressed down to something like.

device [info, mac, name, provision]

then when I type meadow device --help it would expand to the full description as per the initial example, but just for that command group.

Screenshot 2023-04-13 at 18 48 10
Tyrrrz commented 1 year ago

@CartBlanche this is a bit unrelated to this issue (it talks about option groups), but you can achieve exactly what you want by creating a dummy command, e.g. device that just throws a CommandException on execution. You can configure the exception to guide the user to child commands and also automatically show the help text.

[Command("device")]
public class DeviceCommand : ICommand
{
    public ValueTask ExecuteAsync(IConsole console) =>
        throw new CommandException("Use one of the child commands", true);
}

This will make all your other device ... commands nest underneath this device command.