Add help command

Added a help command line option that shows command line syntax and
available options.
This commit is contained in:
luca0N! 2022-06-09 22:44:44 -03:00
parent 5058545c22
commit 9eb5c21451
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
1 changed files with 15 additions and 2 deletions

View File

@ -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;
}