4 ms·
It’s unfortunate that Go’s standard package `flag` doesn’t follow the standard either, given the language is otherwise a good fit for command-line tools.
by pansa2 6y ago
It’s unfortunate that Go’s standard package `flag` doesn’t follow the standard either, given the language is otherwise a good fit for command-line tools.
- vitus 6y agoBy standard, do you mean -s for short flag, and --two_dashes_for_long_flags? Because if you don't care about chaining together short flags and just want to use two dashes for your long flags, Go will happily accept that. https://golang.org/pkg/flag/ https://golang.org/pkg/flag/ : "One or two minus signs may be used; they are equivalent."
- tqkxzugoaupvwqr 6y agoBut help prints single dash for long flags which contributes to the fall of double dash long flags.
- vitus 6y agoOh, I agree. I ran into a related issue a couple of years back where people were using single-dash flags for a C++ project that was using Abseil flags in conjunction with getopt parsing of short flags (for legacy reasons). Why were they using single-dash flags, despite that not showing up anywhere in our documentation? They copy-pasted from --help. (I'm happy to say that --help in Abseil has since been fixed.)
- eyelidlessness 6y agoBut that doesn’t preclude mistakes by collision (N short flags match a long one) or unpredictable bugs in a long flag interpreter (a short flag being a substring of a long one)—both being trivially common bugs when this ambiguity is allowed, especially when an API is ported to another environment with less tooling standardization around interpreting the input.
- vitus 6y agoGo doesn't allow for specifying multiple short flags all run together, or for flag args without spaces, so neither of those are directly relevant here. Also, that first issue happens with POSIX flags (with the GNU long flag extension, anyhow): `grep -help` is different from `grep --help` (and if you type the former, it'll just wait patiently for you to close stdin).
- neolog 6y agoBecause of Go, I have to monitor what language a command-line program is written in before using it.
- deleted 6y ago[deleted]