cli icon indicating copy to clipboard operation
cli copied to clipboard

Combine behavioral struct fields into sub-struct groupings

Open meatballhat opened this issue 2 years ago • 1 comments

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 :arrow_right: Help.Hidden
  • HideHelpCommand :arrow_right: Help.CommandHidden

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

  • EnableShellCompletion :arrow_right: ShellCompletion.Enabled
  • ShellCompletionCommandName :arrow_right: 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 🙇🏼

meatballhat avatar Jun 30 '23 13:06 meatballhat

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

bartekpacia avatar May 02 '24 16:05 bartekpacia