Skip to content

Support grouping options in help #2216

Open

Description

@hach-que

Currently the options output for my program looks like this:

Description:
  Build an Unreal Engine project or plugin.

Usage:
  uet build [options]

Options:
  -e, --engine <engine>                                        The engine to use for the build. []
  -p, --path <path>                                            The directory path that contains a .uproject file, a .uplugin file, or a BuildConfig.json file. If this parameter isn't provided, defaults to the current working directory. [default: C:\Work\internal
                                                               (BuildConfig.json)]
  -d, --distribution <distribution>                            The distribution to build if targeting a BuildConfig.json file. []
  --shipping                                                   If set, builds for Shipping instead of Development. Only valid when not using a BuildConfig.json file to build.
  -x, --executor <gitlab|local>                                The executor to use. [default: local]
  --executor-output-file <executor-output-file>                If the executor runs the build externally (e.g. a build server), this is the path to the emitted file that should be passed as the job or build description into the build server.
  --windows-shared-storage-path <windows-shared-storage-path>  If the build is running across multiple machines (depending on the executor), this is the network share for Windows machines to access.
  --windows-sdks-path <windows-sdks-path>                      If set, UET will automatically manage and install platform SDKs, and store them in the provided path on Windows machines. This should be a local path; the SDKs will be installed on each machine as they're
                                                               needed.
  --mac-shared-storage-path <mac-shared-storage-path>          If the build is running across multiple machines (depending on the executor), this is the local path on macOS pre-mounted to the network share.
  --mac-sdks-path <mac-sdks-path>                              If set, UET will automatically manage and install platform SDKs, and store them in the provided path on macOS machines. This should be a local path; the SDKs will be installed on each machine as they're
                                                               needed.
  --test                                                       If set, executes the tests after building.
  --deploy                                                     If set, executes the deployment after building (and testing if --test is set).
  --strict-includes                                            If set, disables unity and PCH builds. This forces all files to have the correct #include directives, at the cost of increased build time.
  -?, -h, --help                                               Show help and usage information

I would like to be able to customize the help output by assigning options and arguments to "groups", so that I can get help output like this instead:

Description:
  Build an Unreal Engine project or plugin.

Usage:
  uet build [options]

Options:
  -e, --engine <engine>                                        The engine to use for the build. []
  -p, --path <path>                                            The directory path that contains a .uproject file, a .uplugin file, or a BuildConfig.json file. If this parameter isn't provided, defaults to the current working directory. [default: C:\Work\internal
                                                               (BuildConfig.json)]
  --test                                                       If set, executes the tests after building.
  --deploy                                                     If set, executes the deployment after building (and testing if --test is set).
  --strict-includes                                            If set, disables unity and PCH builds. This forces all files to have the correct #include directives, at the cost of increased build time.
  -?, -h, --help                                               Show help and usage information.

Options when targeting a BuildConfig.json file:
  -d, --distribution <distribution>                            The distribution to build if targeting a BuildConfig.json file. []

Options when targeting a .uplugin or .uproject file:
  --shipping                                                   If set, builds for Shipping instead of Development

Options when building on CI/CD:
  -x, --executor <gitlab|local>                                The executor to use. [default: local]
  --executor-output-file <executor-output-file>                If the executor runs the build externally (e.g. a build server), this is the path to the emitted file that should be passed as the job or build description into the build server.
  --windows-shared-storage-path <windows-shared-storage-path>  If the build is running across multiple machines (depending on the executor), this is the network share for Windows machines to access.
  --windows-sdks-path <windows-sdks-path>                      If set, UET will automatically manage and install platform SDKs, and store them in the provided path on Windows machines. This should be a local path; the SDKs will be installed on each machine as they're
                                                               needed.
  --mac-shared-storage-path <mac-shared-storage-path>          If the build is running across multiple machines (depending on the executor), this is the local path on macOS pre-mounted to the network share.
  --mac-sdks-path <mac-sdks-path>                              If set, UET will automatically manage and install platform SDKs, and store them in the provided path on macOS machines. This should be a local path; the SDKs will be installed on each machine as they're
                                                               needed.

I tried to customize the options output through HelpBuilder, but ran into the problem mentioned in #2215 where it uses a bunch of internals that are not accessible:

image

Activity

  1. seanadams9 commented on Jun 9, 2023

    @seanadams9

    You can copy over the ParentNode class and then use:

    ParentNode? parent = new ParentNode(current.Parents.FirstOrDefault());

    The IsGlobal in the latest build isn't there anymore, using this now:

                         if (option is { Recursive: true, Hidden: false })
                                        {
                                            if (option is not HelpOption || !addedHelpOption)
                                            {
                                                optionRows.Add(this.GetTwoColumnRow(option, ctx));
                                            }
                                        }
    

    I just copied over the WriteHeading functionality to use it.

    For WasSectionSkipped I'm still working out a way to handle it, current thoughts are having my own List of skipped sections that I add to since I can't use the WasSectionSkipped in the help context.

  2. hach-que commented on Jul 13, 2023

    @hach-que
    Author

    I ended up forking System.CommandLine and added an ArgumentGroupName to options. It can be downloaded here: https://www.nuget.org/packages/Redpoint.ThirdParty.System.CommandLine

  3. KalleOlaviNiemitalo commented on Oct 31, 2024

    @KalleOlaviNiemitalo

    With System.CommandLine 2.0.0-beta4.22272.1, I was able to set up option groups in help by using CommandLineBuilderExtensions.UseHelp(this CommandLineBuilder builder, Action<HelpContext> customize, int? maxWidth = null) and HelpBuilder.CustomizeLayout(Func<HelpContext, IEnumerable<HelpSectionDelegate>> getLayout), and then replacing HelpBuilder.Default.OptionsSection() with a HelpSectionDelegate that writes a TwoColumnHelpRow[] that contains group headings and options. For each group heading, FirstColumnText is the heading text, and SecondColumnText is an empty string. This hack does not allow a heading to span both columns, but my headings are short enough that it does not matter.

    To get blank lines between groups, I originally tried new TwoColumnHelpRow("", ""), but HelpBuilder.WriteColumns ignored those altogether. Instead, I prepend a newline character to each heading except the first.

    I also tried outputting each option group with a separate HelpBuilder.WriteColumns call, but then the columns were not aligned between option groups, and that looked rather ugly.

    Prior art for option groups is in Argp Option Vectors (The GNU C Library).

  4. fergusonr commented on Apr 17, 2026

    @fergusonr

    I have the same requirement. I would have thought this is quite a common requirement. Just look at the help of these as examples:-

    robocopy --help
    dotnet --help
    git --help
    wsl --help

    For this reason, I think this should be a feature natively supported rather than having to go down the custom HelpBuilder route.

    I did go down the same path as @hach-que and created a proof-of-concept implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions