I'm writing a console application which allows several Posix flags to be set.
This is what I'm using currently. Words in the flags are concatenated with a dash:
-p, --broker-port int Broker Port (default 1883)
-u, --broker-url string Broker URL (default "localhost")
-c, --client-id string MQTT Client Id
-r, --room string Room where sensor is located (default "myroom")
-f, --floor string Floor, where room is located (default "basement")
However I have also seen applications using CamelCase to concatenate pflags.
The official GNU coding standard does not specify how to concatenate words in posix flags.
What is the right way?
Thanks
The most important rule when naming your flags is to try to be as detailed and descriptive as possible. This will make it easier for people in your organization to determine what this flag is for and what it does. The more detailed, the less the margin for confusion and error.
The first character of the name should be a letter and all characters (except the period) should be lower-case letters and numbers. The base name should be eight or fewer characters and the suffix should be three or fewer characters (four, if you include the period).
The answer seems to be buried in the GNU docs here.
GNU adds long options to these conventions. Long options consist of ‘--’ followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique.
What you've got follows the convention; camel case does not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With