Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine behavioral struct fields into sub-struct groupings #1791

Open
Tracked by #1531
meatballhat opened this issue Jun 30, 2023 · 1 comment
Open
Tracked by #1531

Combine behavioral struct fields into sub-struct groupings #1791

meatballhat opened this issue Jun 30, 2023 · 1 comment
Labels
area/v3 relates to / is being considered for v3 kind/cleanup describes internal cleanup / maintaince kind/feature describes a code enhancement / feature request
Milestone

Comments

@meatballhat
Copy link
Member

meatballhat commented Jun 30, 2023

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

@meatballhat meatballhat added this to the Release 3.x milestone Jun 30, 2023
@meatballhat meatballhat added kind/feature describes a code enhancement / feature request kind/cleanup describes internal cleanup / maintaince labels Jun 30, 2023
@meatballhat meatballhat added the area/v3 relates to / is being considered for v3 label Apr 27, 2024
@bartekpacia
Copy link
Contributor

bartekpacia commented May 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v3 relates to / is being considered for v3 kind/cleanup describes internal cleanup / maintaince kind/feature describes a code enhancement / feature request
Projects
None yet
Development

No branches or pull requests

2 participants