GopherCon 2019 - Design Command-Line Tools that People Love
These are some notes from my experiences at the GopherCon 2019. I don’t expect these will be laid out in any particularly useful way; I am mostly taking them so I can remember some of the bits I found most useful in the future.
-
Presenter likes subcommands that read like sentences (cmd verb noun [name] [–flags])
- Saying things out loud and it sounding good is a nice guide
-
Follow precendent in naming when it makes sense (easier transitions)
-
Always machine output format option (json)
-
Default human first output
-
Multiple positional args only when order doesn’t matter
-
go-humanize for relative datetimes, byte sizes, plurals, etc
-
Good help text (examples)
-
Aliases / shortcuts / good defaults are nice for humans (e.g., skip verbs or nouns when it makes sense)
-
Task-bundled commands are nice for humans
-
Needs high quality code behind it
- Reliable
- Good error messages / help
- Maintainable and testable
-
Recommends cobra
- But still have to think about testing etc
-
Design package(s), not just a cli
-
Pro-tip: keep
viper
isolated -
cobra
helperPreRunE
– called after flags but before run