Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for posix flags

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

like image 378
dh1tw Avatar asked Jan 27 '17 16:01

dh1tw


People also ask

How do you name a flag?

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.

What is the naming convention in C?

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).


1 Answers

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.

like image 159
noelob Avatar answered Oct 25 '22 17:10

noelob