Skip to content

Commit f83f741

Browse files
committed
bossac: add -V/--version command-line option
* It's helpful to get the version number without the whole verbose help text. Add -V/--version option for this like many other utilities. * Move help text for -h/-V to the bottom of the list so they're not mixed in with other behavior options. * Exit with a success return code (0) instead of failure (1) on -h/-V, as is conventional.
1 parent 3279031 commit f83f741

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

src/bossac.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ class BossaConfig
6363
bool security;
6464
bool info;
6565
bool debug;
66-
bool help;
6766
bool usbPort;
6867
bool arduinoErase;
68+
bool help;
69+
bool version;
6970

7071
int readArg;
7172
int offsetArg;
@@ -91,9 +92,10 @@ BossaConfig::BossaConfig()
9192
lock = false;
9293
security = false;
9394
info = false;
94-
help = false;
9595
usbPort = false;
9696
arduinoErase = false;
97+
help = false;
98+
version = false;
9799

98100
readArg = 0;
99101
offsetArg = 0;
@@ -237,11 +239,6 @@ static Option opts[] =
237239
{ ArgNone },
238240
"print debug messages"
239241
},
240-
{
241-
'h', "help", &config.help,
242-
{ ArgNone },
243-
"display this help text"
244-
},
245242
{
246243
'U', "usb-port", &config.usbPort,
247244
{ ArgOptional, ArgInt, "BOOL", { &config.usbPortArg } },
@@ -257,7 +254,17 @@ static Option opts[] =
257254
'a', "arduino-erase", &config.arduinoErase,
258255
{ ArgNone },
259256
"erase and reset via Arduino 1200 baud hack"
260-
}
257+
},
258+
{
259+
'h', "help", &config.help,
260+
{ ArgNone },
261+
"display this help text"
262+
},
263+
{
264+
'V', "version", &config.version,
265+
{ ArgNone },
266+
"display version info"
267+
},
261268
};
262269

263270
int
@@ -324,22 +331,27 @@ main(int argc, char* argv[])
324331
return help(argv[0]);
325332
}
326333

327-
if (config.help)
334+
if (config.help || config.version)
328335
{
329-
printf("Usage: %s [OPTION...] [FILE]\n", argv[0]);
336+
if (config.help)
337+
printf("Usage: %s [OPTION...] [FILE]\n", argv[0]);
330338
printf("Basic Open Source SAM-BA Application (BOSSA) Version " VERSION "\n"
331339
"Flash programmer for Atmel SAM devices.\n"
332340
"Copyright (c) 2011-2018 ShumaTech (http://www.shumatech.com)\n"
333-
"\n"
334-
"Examples:\n"
335-
" bossac -e -w -v -b image.bin # Erase flash, write flash with image.bin,\n"
336-
" # verify the write, and set boot from flash\n"
337-
" bossac -r0x10000 image.bin # Read 64KB from flash and store in image.bin\n"
338341
);
339-
printf("\nOptions:\n");
340-
cmd.usage(stdout);
341-
printf("\nReport bugs to <bugs@shumatech.com>\n");
342-
return 1;
342+
if (config.help)
343+
{
344+
printf("\n"
345+
"Examples:\n"
346+
" bossac -e -w -v -b image.bin # Erase flash, write flash with image.bin,\n"
347+
" # verify the write, and set boot from flash\n"
348+
" bossac -r0x10000 image.bin # Read 64KB from flash and store in image.bin\n"
349+
);
350+
printf("\nOptions:\n");
351+
cmd.usage(stdout);
352+
printf("\nReport bugs to <bugs@shumatech.com>\n");
353+
}
354+
return 0;
343355
}
344356

345357
try

0 commit comments

Comments
 (0)