Skip to content

Combine behavioral struct fields into sub-struct groupings #1791

Closed as not planned

Description

@meatballhat

Some of the fields on Command are related and may be grouped together for clarity. For example, these Help.+ fields could be grouped together under a Help field:

  • HideHelp ➡️ Help.Hidden
  • HideHelpCommand ➡️ Help.CommandHidden

or these fields related to shell completion could be under a ShellCompletion field:

  • EnableShellCompletion ➡️ ShellCompletion.Enabled
  • ShellCompletionCommandName ➡️ ShellCompletion.CommandName

or all of these could be grouped under an Options or Config field (?):

cmd := &cli.Command{
    Name: "foo",
    Config: cli.CommandConfig{
        HideHelp: true,
        EnableShellCompletion: true,
    },
}

There are arguable tradeoffs, of course, such as:

  • nested fields are more difficult to reason about and more visually complex than a single level of fields
  • logical groupings of fields "hides" them from each other
  • depending on the "zero value" of simple types means that default values for certain behaviors are tightly coupled to the field names, e.g. HideSomething (default on) vs. EnableSomething (default off)
  • others I'm surely not thinking about

Ideas and questions and concerns wanted 🙇🏼

Activity

  1. added this to the Release 3.x milestone on Jun 30, 2023
  2. added
    kind/feature
    kind/cleanup
    on Jun 30, 2023
  3. added
    area/v3
    on Apr 27, 2024
  4. bartekpacia commented on May 2, 2024

    @bartekpacia
    Member

    I understand this issue, but I think the way it is currently is just... good enough. I also think that the less we break from v2, the better.

    "Flat is better than nested." - The Zen of Python

  5. dearchap commented on Oct 26, 2024

    @dearchap
    Contributor

    Lets keep it for v2 compatibility.

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

    area/v3kind/cleanupkind/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions