Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command-line Options: Should short options be restricted to 1 character?

I'm trying to get my head around command-line arguments for Python and have been reading the Standard Library documentation about the argparse module. They mention the concept of short and long form command-line options, with short form options specified with a single dash, - (eg -f), and long form options specified with two dashes, -- (eg --filename).

Nowhere does it describe the difference between the short form and long form options, except that one is obviously shorter than the other. After Googling the concepts it seems to me short form options originated long ago in C. Back then they were a single character.

My question is, should I continue to use only a single character for short form command-line options in Python? Is that what users will expect? Or is it acceptable to use two of three character abbreviations in the short options (eg -fn)?

like image 346
Simon Tewsi Avatar asked Aug 16 '13 09:08

Simon Tewsi


People also ask

What is the maximum combined length of characters in the command line arguments?

The maximum length of the string that you can use at the command prompt is 8191 characters.

Which is concern with command line argument?

On most UNIX platforms, command-line argument processing is handled using the getopt function. This function parses arguments passed to a program via the command line, with each option and possible argument made available to the programmer via a switch statement.

What is Store_true in Python?

The store_true option automatically creates a default value of False. Likewise, store_false will default to True when the command-line argument is not present. The source for this behavior is succinct and clear: http://hg.python.org/cpython/file/2.7/Lib/argparse.py#l861.


1 Answers

I believe we could make a reference for POSIX standard and GNU coding guidelines. Despite there isn't a sort of 'global' standard, I suppose we should stick to these rules at least while we code for *nix.

According to the POSIX conventions each option name should be a single alphanumeric character (the alnum character classification) from the portable character set. And all options should be preceded by the '-' delimiter character.

GNU guideline adds long options

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.

like image 106
Pavel Sapezhka Avatar answered Oct 02 '22 01:10

Pavel Sapezhka