Skip to content

Support for showing Subgroups / Subcommands in Help print #123

Closed as not planned
@BlackPhlox

Description

@BlackPhlox

Hi there 👋
Thanks for creating this awesome framework and putting effort into maintaining it!
I'm currently working on a CLI and using this framework when I stumbled upon a limitation:

When implementing subcommands in ones CLI, it can feel overwhelming and cluttered that all commands including all sub-commands being shown in the help print, when in my opinion, the help should only show first level of the hierarchy. Which is usually the case for CLI's with many commands such as Azure's CLI az, which have something called subgroups, which is a group of commands under a command. ConsoleAppFramework should allow to express the this type of hierarchy as well.

Related StackOverflow question by Stephen Gilboy:
https://stackoverflow.com/questions/72913198/in-cysharp-consoleappframework-how-can-i-create-a-sub-sub-command

How it is currently

Given:

// Program.cs
var app = ConsoleApp.Create();
app.Add<KeyVaultCommands>("kv");
app.Run(args);

// ... 
public class KeyVaultCommands
{
    /// <summary>KeyVault - Manage Azure Key Vault Secrets</summary>
    /// <param name="msg">-m, Message to show.</param>
    [Command("")]
    public void Root(string msg) => Console.WriteLine(msg);

    /// <summary>
    /// Prompts installs for the nessary cli to interact with Azure KeyVault
    /// </summary>
    /// <param name="msg"></param>
    [Command("setup")]
    public void Setup(string msg) => Console.WriteLine(msg);
}

Produces result:

> MyCLI.exe
Usage: [command] [-h|--help] [--version]

Commands:
  kv          KeyVault - Manage Azure Key Vault Secrets
  kv setup    Prompts installs for the nessary cli to interact with Azure KeyVault

Notice how the setup command is not shown here, even though they start with the same command keyword:

> MyCLI.exe kv
Usage: kv  [options...] [-h|--help] [--version]

KeyVault - Manage Azure Key Vault Secrets

Options:
  -m|--msg <string>    Message to show. (Required)

How it could look like:

// Program.cs
var app = ConsoleApp.Create();
app.Add<KeyVaultCommands>("kv");
app.Run(args);

// ... 
public class KeyVaultCommands
{
    /// <summary>KeyVault - Manage Azure Key Vault Secrets</summary>
    /// <param name="msg">-m, Message to show.</param>
    [Command("")]
    public void Root(string msg) => Console.WriteLine(msg);

    /// <summary>
    /// Prompts installs for the nessary cli to interact with Azure KeyVault
    /// </summary>
    /// <param name="msg"></param>
    [Command("setup", CommandType.Hidden )] // More enum types could be: Default (Current behaviour), Hidden (The showcase behavior in this issue), Indented (Show as an ASCII tree of the hierarchy of its command parent)
    public void Setup(string msg) => Console.WriteLine(msg);
}
> MyCLI.exe
Usage: [command] [-h|--help] [--version]

Commands:
  kv          KeyVault - Manage Azure Key Vault Secrets

Here below at Commands: it could also be called Subgroups: or the like. Note: I'm also unsure of how the Usage: syntax should look like, currently I've just added a | to indicate or:

>MyCLI.exe kv
Usage: kv [command] | [options...] [-h|--help] [--version]

KeyVault - Manage Azure Key Vault Secrets

Commands:
  setup    Prompts installs for the nessary cli to interact with Azure KeyVault

Options:
  -m|--msg <string>    Message to show. (Required)

If able, please let me know if there's any edgecases or something that I havn't considered due to how the framework is structured.
I'll might take a crack at in the next week or so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions