Skip to content

Combine behavioral struct fields into sub-struct groupings #1791

@meatballhat

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 🙇🏼

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v3relates to / is being considered for v3kind/cleanupdescribes internal cleanup / maintaincekind/featuredescribes a code enhancement / feature request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions