Add help command
Added a help command line option that shows command line syntax and available options.
This commit is contained in:
parent
5058545c22
commit
9eb5c21451
17
src/main.cxx
17
src/main.cxx
|
@ -40,6 +40,12 @@ void printUsage(const char *programName) {
|
|||
<< std::endl;
|
||||
}
|
||||
|
||||
void print_help(const char *program_name) {
|
||||
printUsage(program_name);
|
||||
std::cout << " -h, --help\t\tShows this help message.\n"
|
||||
<< " -v, --verbose\t\tPrints additional messages to standard output.\n";
|
||||
}
|
||||
|
||||
void printIntro() {
|
||||
printf("%s v%s (%d)\nCopyright (C) %s %s\n\n",
|
||||
PROGRAM_NAME, PROGRAM_VERSION_NAME, PROGRAM_VERSION,
|
||||
|
@ -60,6 +66,9 @@ int main(int argc, char *argv[]) {
|
|||
if (strcmp(argv[argi], "--verbose") == 0) {
|
||||
verbose = true;
|
||||
std::cout << "Verbose output enabled.\n";
|
||||
} else if (strcmp(argv[argi], "--help") == 0) {
|
||||
print_help(argv[0]);
|
||||
exit(RETURN_SUCCESSFUL);
|
||||
} else {
|
||||
std::cerr << "error: unknown command line option `" <<
|
||||
argv[argi] << "'." << std::endl;
|
||||
|
@ -72,9 +81,13 @@ int main(int argc, char *argv[]) {
|
|||
verbose = true;
|
||||
std::cout << "Verbose output enabled.\n";
|
||||
break;
|
||||
case 'h':
|
||||
print_help(argv[0]);
|
||||
exit(RETURN_SUCCESSFUL);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "error: unknown command line option `" <<
|
||||
argv[argi] << "'." << std::endl;
|
||||
std::cerr << "error: unknown command line option `-" <<
|
||||
argv[argi][i] << "'." << std::endl;
|
||||
exit(RETURN_FAILED_INVALID_SYNTAX);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue