3 ms·
I pretty like the consistency of esbuild CLI [1]. It has three kinds of options: 1. no-valued option: --example 2. single-valued option: --key=value 3. multi-v
by conaclos 4y ago
I pretty like the consistency of esbuild CLI [1].
It has three kinds of options:
1. no-valued option: --example
2. single-valued option: --key=value
3. multi-valued option: --elements:1st --elements:2nd
Short options are ruled out, although it accepts the short option -h for discoverability.
I particularly like the repeated option pattern for multi-valued options. This avoids ambiguities such as:
cli --elements 1st 2nd arg
Yes, the ambiguity may be removed by using doubled dashes. However, this is error-prone.
I often wondering whether a more familiar syntax for the second and third kinds could be adopted. For instance:
--key value
--elements 1st --elements 2nd
[1] https://github.com/evanw/esbuild https://github.com/evanw/esbuild
- bbkane 4y agoThis is largely what the Azure CLI does. It simplifies even further by eliminating the no-value option. Instead, you pass "true" or "false" as the value ( --example true ). It's a little more verbose but very easy to parse/write/generate. I like this convention so much I stole it for my homemade Golang CLI parsing library https://github.com/bbkane/warg/ https://github.com/bbkane/warg/ .