All: Add --help flag for command line programs

This commit is contained in:
Jeffrey Pfau 2015-05-10 03:02:03 -07:00
parent a651a91aa1
commit 6f24064f4f
5 changed files with 14 additions and 6 deletions

View File

@ -63,6 +63,7 @@ Misc:
- GBA Thread: Add functionality for running callbacks on the GBA thread
- Qt: Fast forward (held) option moved from Other to Emulation menu
- GBA Memory: Soft-crash if jumping past the end of a ROM
- All: Add --help flag for command line programs
0.2.0: (2015-04-03)
Features:

View File

@ -43,6 +43,7 @@ static const struct option _options[] = {
#ifdef USE_GDB_STUB
{ "gdb", no_argument, 0, 'g' },
#endif
{ "help", no_argument, 0, 'h' },
{ "movie", required_argument, 0, 'v' },
{ "patch", required_argument, 0, 'p' },
{ 0, 0, 0, 0 }
@ -53,7 +54,7 @@ bool _parseGraphicsArg(struct SubParser* parser, struct GBAConfig* config, int o
bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int argc, char* const* argv, struct SubParser* subparser) {
int ch;
char options[64] =
"b:c:Dl:p:s:v:"
"b:c:Dhl:p:s:v:"
#ifdef USE_CLI_DEBUGGER
"d"
#endif
@ -93,6 +94,9 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg
opts->debuggerType = DEBUGGER_GDB;
break;
#endif
case 'h':
opts->showHelp = true;
break;
case 'l':
GBAConfigSetDefaultValue(config, "logLevel", optarg);
break;
@ -117,7 +121,7 @@ bool parseArguments(struct GBAArguments* opts, struct GBAConfig* config, int arg
argc -= optind;
argv += optind;
if (argc != 1) {
return false;
return opts->showHelp;
}
opts->fname = strdup(argv[0]);
return true;

View File

@ -30,6 +30,7 @@ struct GBAArguments {
enum DebuggerType debuggerType;
bool debugAtStart;
bool showHelp;
};
struct SubParser {

View File

@ -62,12 +62,13 @@ int main(int argc, char** argv) {
GBAConfigLoadDefaults(&config, &opts);
struct GBAArguments args;
if (!parseArguments(&args, &config, argc, argv, &subparser)) {
bool parsed = parseArguments(&args, &config, argc, argv, &subparser);
if (!parsed || args.showHelp) {
usage(argv[0], PERF_USAGE);
freeArguments(&args);
GBAConfigFreeOpts(&opts);
GBAConfigDeinit(&config);
return 1;
return !parsed;
}
renderer.outputBuffer = malloc(256 * 256 * 4);

View File

@ -59,12 +59,13 @@ int main(int argc, char** argv) {
struct SubParser subparser;
initParserForGraphics(&subparser, &graphicsOpts);
if (!parseArguments(&args, &config, argc, argv, &subparser)) {
bool parsed = parseArguments(&args, &config, argc, argv, &subparser);
if (!parsed || args.showHelp) {
usage(argv[0], subparser.usage);
freeArguments(&args);
GBAConfigFreeOpts(&opts);
GBAConfigDeinit(&config);
return 1;
return !parsed;
}
GBAConfigMap(&config, &opts);