C getopt multiple value

I know this is quite old but I came across this in my search for a solution. while((command = getopt(argc, argv, “a:”)) != -1){ switch(command){ case ‘a’: (…) optind–; for( ;optind < argc && *argv[optind] != ‘-‘; optind++){ DoSomething( argv[optind] ); } break; } I found that int optind (extern used by getopt() ) points … Read more

Optional option argument with getopts

Wrong. Actually getopts does support optional arguments! From the bash man page: If a required argument is not found, and getopts is not silent, a question mark (?) is placed in name, OPTARG is unset, and a diagnostic message is printed. If getopts is silent, then a colon (:) is placed in name and OPTARG … Read more

Why use argparse rather than optparse?

As of python 2.7, optparse is deprecated, and will hopefully go away in the future. argparse is better for all the reasons listed on its original page (https://code.google.com/archive/p/argparse/): handling positional arguments supporting sub-commands allowing alternative option prefixes like + and / handling zero-or-more and one-or-more style arguments producing more informative usage messages providing a much … Read more