Writing Consistent Tools (2019)
netmeister.org
netmeister.org
Is it a tool like Git, that you run over and over again, many times throughout the day?
Or is it something like 'find', where you run it every once in a while, but aren’t used to using it?
Or is it something like 'ld', where you only ever run it from your build system?
Tools like Git it's nice to have options like -p for --patch.
Tools you only use from build scripts—easy enough to only give them long options. You don't need short options, mostly. Same goes for tools that are only written seldom. You won’t remember what the short options mean, for a tool that you run once or twice a month, so you’re just shooting yourself in the foot by using them.
The standard is -o --output flag for specifying a different format than plan plain text.
I think that one important thing about writing consistent and powerful tools is having clear and remindable subcommands and flags, i feel like i'm writing a narrative when i'm working with Vault and AWS CLI, they are incredibly well designed.
If the tool generates some table-like output, then -o/--output usually allows changing what exactly is output. E.g. lsblk -o +model.
For different output formats I've seen -f/--format {text,json,xml}, might be a bit verbose. --json is probably fine. Short version needed? Probably not.