p-ranav / argparse

Argument Parser for Modern C++
MIT License
2.72k stars 250 forks source link

In usage message, it feels strange to have a required argument in "Optional arguments" section #340

Open nmoreaud opened 8 months ago

nmoreaud commented 8 months ago

Currently, argparse distinguishes "positional arguments" and "optional arguments". I wonder if "optional arguments" should be splitted into 2 separate categories: "named arguments" and "optional arguments", so that required arguments are listed first. Or rename "Optional arguments" into "Named arguments", because it feels weird to have a required argument in "Optional arguments" section.

Also, positional arguments are listed first, but in "Usage: " line, input is the last parameter

Usage: main [--help] [--verbose] --configuration VAR [--optional1 VAR] [--optional2 VAR] [--optional3 VAR] input

A description

Positional arguments:
  input                      json input file [required]

Optional arguments:
  -h, --help                 shows help message and exits 
  -v, --verbose              verbose output 
  -c, --configuration        propagation model configuration [required]
  --optional1              optional argument 1
  --optional2              optional argument 2
  --optional3              optional argument 3

vs

Usage: main [--help] [--verbose] --configuration VAR [--optional1 VAR] [--optional2 VAR] [--optional3 VAR] input

A description

Positional arguments:
  input                      json input file [required]

Named arguments:
  -c, --configuration        propagation model configuration [required]

Optional arguments:
  -h, --help                 shows help message and exits 
  -v, --verbose              verbose output 
  --optional1              optional argument 1
  --optional2              optional argument 2
  --optional3              optional argument 3