Skip to content

Commit

Permalink
Add support for long options, and --help option
Browse files Browse the repository at this point in the history
Switch from getopt() to getopt_long() and add a long "--help" argument
as alias to the "-?" argument.

Note that the getopt_long() function is available on GNU, BSD, and the
existing msvc/getopt.[ch] already implements getopt_long() on Windows.
  • Loading branch information
ndim committed Aug 24, 2024
1 parent 9e9825c commit 9873a32
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static void usage(void) {
" -v Verbose output; -v -v for more\n"
" -q Quell progress output; -q -q for less\n"
" -l logfile Use logfile rather than stderr for diagnostics\n"
" -? Display this usage\n"
" -? | --help Display this usage\n"
"\navrdude version %s, https://github.com/avrdudes/avrdude\n",
progname, strlen(cfg) < 24? "config file ": "", cfg, AVRDUDE_FULL_VERSION);

Expand Down Expand Up @@ -814,7 +814,12 @@ int main(int argc, char *argv[]) {
#endif

// Process command line arguments
while((ch = getopt(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:")) != -1) {
struct option longopts[] = {
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
while((ch = getopt(argc, argv, "?Ab:B:c:C:DeE:Fi:l:nNp:OP:qrtT:U:vVx:",
longopts, NULL)) != -1) {
switch(ch) {
case 'b': // Override default programmer baud rate
baudrate = str_int(optarg, STR_INT32, &errstr);
Expand Down

0 comments on commit 9873a32

Please sign in to comment.