CLI Flag Parsing Conventions

The cluster discusses conventions for command-line argument parsing, including single-dash vs double-dash options, adherence to GNU standards like getopt_long, and suggestions for better libraries such as argparse alternatives or docopt.

➡️ Stable 0.5x Open Source
2,896
Comments
19
Years Active
5
Top Authors
#2550
Topic ID

Activity Over Time

2008
6
2009
29
2010
26
2011
46
2012
70
2013
116
2014
122
2015
126
2016
134
2017
117
2018
122
2019
172
2020
329
2021
310
2022
350
2023
272
2024
234
2025
307
2026
8

Keywords

e.g CLI OK SUFFIX UNIX opengroup.org GCC ToolLauncherMain NoClassDefFoundError GNU command line command dash line cli flags hadoop arguments gnu flag

Sample Comments

It is sad that many new command-line parsing libraries don't follow the GNU rules anymore. They more often use "-long". Then users have to figure out whether this means "--long" or "-l -o -n -g". To make command line even more confusing, multiple tools I have used allow spaces in optional arguments (e.g. "-opt1 arg1 arg2 -opt2", where arg1 and arg2 set two values for -opt1). Every time I see this, I worry if I could be misusing these tools. I wish eve

soccerdave Nov 26, 2015 View on HN

The lack of double-dash in the stdlib really annoys me. Almost all command line tools use a single dash for single letter arguments (-h) and double-dash for anything longer (--help).

wirthjason May 1, 2023 View on HN

What would make Python better for command line use? Better alternatives to argparse in the standard library?

gkfasdfasdf Jan 18, 2023 View on HN

Am I the only one that thought this was a universal format for describing CLI arguments?

andrewfromx Feb 27, 2023 View on HN

I think they mean why is it sometimes "./foo --help" vs "./foo -h" or "./thing --other=123 --value=456" but sometimes "./thing -o 123 -v 456"

Just go through the docs. They have a ton of single hyphen long opts that aren't a letter with argument.

LegibleCrimson Mar 17, 2024 View on HN

No, that's how optional flags should work. I mean how specifically -i works. With GNU sed:-lN, --line-length=N, -l N, --line-length NAll work the same, set line length to N.-iSUFFIX --in-place=SUFFIX, -i NEXTARG --in-place NEXTARGDon't all work the same. The argument is only actually taken if it's attached to the flag directly. In the latter two forms, no backup is made.GNU mktemp is similarly annoying, but different, with the --tmpdir flag.-pDIR, --tmpdir=DI

rossy Oct 12, 2016 View on HN

I'd expand on this and say every command line program should support GNU getopt_long() syntax, since this is the most popular syntax for command line interfaces and it saves having to guess the syntax when using a program for the first time. This doesn't mean all programs should use getopt_long(), but they should understand all the syntax that getopt_long() understands, such that someone could reimplement the program's command line interface using getopt_long() and get exactly the

kevin_thibedeau Feb 10, 2025 View on HN

Double dash for long args is a GNUism. One which even they don't adhere to uniformly as evidenced by GCC's options.

sumanthvepa May 16, 2025 View on HN

Getopt and its brethren in other languages are starting to get long in the tooth. Modern CLI tools need more flexible parsing.