Defining CLI Flag Naming Conventions #8446
Replies: 4 comments 11 replies
-
My 2c: Singular vs. PluralOften times the flag is more extensible if pluralized from the beginning. An example of this are those flags where lists (multiple inputs) are involved. We may only have one input for the flag today but if tomorrow things change and now we require to pass in multiple inputs, we don't need to change the flag (or add aliases) we've seen this before in Trivy when renaming the flags for checks. One could argue that a singular flag could also support taking in a list of inputs but to me it feels a bit odd to specify a list for a flag that is singular to read. Another point somewhat related to this are boolean flags. They are quite limiting in nature and should be used sparingly. A recent example of that could be found here in this discussion: #8360 (comment) In this case I actually suggested the use of a boolean flag at first but I realized that there's a better way for us to restructure it by making it into a flag that accepts a list as @nikpivkin suggested. Abbreviations vs. Full NamesI would vote for long flags to always be fully spelt out and for their short aliases to be compacted. For example: I say this as the IMHO the main reason why long flags exist is to help the relatively new user understand the functionality fully, given the high readability and verbosity of the long flags. Power users (and/or automation) can benefit from the short flags where readability isn't a key concern but brevity might be preferred. |
Beta Was this translation helpful? Give feedback.
-
About plural/singular I think there are 3 issues:
For example, the flag The reference you gave of Docker is supporting my claim that these issues are conflated. You presented it as singular but the examples aren't decisive. Issue 1 Issue 2 Issue 3 |
Beta Was this translation helpful? Give feedback.
-
About Abbreviations vs. Full Names I think we should use full names, unless an abbrivation is globally ubiquitous or defined as such by us; in which case it can be used, but consistently. For example, source shouldn't be abbrivated IMO. directory might be abbrivated to dir, since it's ubiquitious (directories should be abbrivated to dirs given my other comment about plurality). I also think it's fine to abbrivate misconfiguration to misconfig since we use it often, but not to misconf since it's inconsistent. Note that this isn't related to short flags (for example, --interactive -> -i) which can still be made available for convenience. |
Beta Was this translation helpful? Give feedback.
-
ChatGPT o1 pro put into words what I couldn't articulate. CLI Flags: Singular vs. Plural1. Why the Distinction MattersDeciding whether a CLI flag (option) should be in singular or plural form may seem trivial, but it has significant implications for usability, consistency, and clarity. Key considerations include:
Many OSS projects (e.g., Docker, Kubernetes, Git) often use singular nouns for flags—even when multiple values are possible—because the mental model is “you specify one item each time you use the flag.” For example, Docker’s 2. Common Guidelines & Examples2.1 OSS Examples
These projects suggest that singular is often chosen when each instance of the flag represents “adding one item.” Repetition then naturally allows multiple items. 2.2 General Criteria for Singular vs. Plural
3. Handling Both Repeated and Batched SpecificationsSometimes, you might allow both repeated usage and batched (comma-/space-separated) usage. For example:
In that scenario, there is no absolute rule for singular or plural; it depends on which method is considered “primary” or more intuitive. Two approaches:
In both cases, clear documentation is crucial. For instance:
4. Proposed Rules for an OSS Project
|
Beta Was this translation helpful? Give feedback.
-
Description
I’d like to open a discussion around formalizing our CLI flag naming conventions, particularly focusing on two key questions:
They are mixed up in Trivy now.
Singular vs. Plural
When should we use
--flag
vs.--flags
?For instance, Docker consistently uses the singular form:
In contrast, the AWS CLI always uses the plural form for list inputs:
Kubectl shows mixed usage; for example, although the --filename flag accepts multiple values, it is named in the singular form:
Abbreviations vs. Full Names
Where do we draw the line between concise flags (e.g.,
--rm
,--db
) and more descriptive flags (--remove
,--database
)? Popular tools vary in their approaches. Docker often uses short forms (--rm
,--env
).These questions came up in a recent PR #8269, where we have several options, like
Our goal is to define a clear, maintainable guideline that balances brevity with clarity.
Points for Discussion
--db-repository,
inherently “feel right” for me (maybe @DmitriyLewen as well) in singular form?I’d love to hear everyone’s thoughts, examples, and experiences to help us build a more consistent and intuitive CLI across our projects.
Beta Was this translation helpful? Give feedback.
All reactions