Skip to content

Commit

Permalink
Merge pull request #24 from chungongyu/dev-c++11
Browse files Browse the repository at this point in the history
fix: return 1 if execute with bad args
  • Loading branch information
chungongyu committed Jul 9, 2020
2 parents d48f3e1 + dd2f2c4 commit c8e30fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
41 changes: 23 additions & 18 deletions src/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,10 @@ class RunnerManager {
return false;
}

int help(int argc, char* argv[]) const {
static std::string shortopt("vh");
static option longopts[] = {
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
int opt = -1;
while ((opt = getopt_long(argc, argv, shortopt.c_str(), longopts, NULL)) != -1) {
switch ((char)opt) {
case 'v':
std::cout << boost::format("%s version %s") % PACKAGE_NAME % PACKAGE_VERSION << std::endl;
return 256;
}
}

int help(int ret = 0) const {
std::cout << boost::format("%s version %s, report bugs to [%s]") % PACKAGE_NAME % PACKAGE_VERSION % PACKAGE_BUGREPORT << std::endl;
std::cout << std::endl;
std::cout << boost::format("usage: %s <command> [<args>]") % PACKAGE_NAME << std::endl;
std::cout << boost::format("Usage: %s <command> [<args>]") % PACKAGE_NAME << std::endl;
std::cout << std::endl;
std::cout << boost::format("The most commonly used %s commands are:") % PACKAGE_NAME << std::endl;

Expand Down Expand Up @@ -129,7 +114,27 @@ class RunnerManager {
std::cout << std::endl;
std::cout << boost::format("See '%s <command> -h' to read about a specific subcommand.") % PACKAGE_NAME << std::endl;
std::cout << boost::format("Further help: %s") % PACKAGE_URL << std::endl;
return 256;

return ret;
}
int help(int argc, char* argv[]) const {
static std::string shortopt("vh");
static option longopts[] = {
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
int opt = -1;
while ((opt = getopt_long(argc, argv, shortopt.c_str(), longopts, NULL)) != -1) {
switch ((char)opt) {
case 'v':
std::cout << boost::format("%s version %s") % PACKAGE_NAME % PACKAGE_VERSION << std::endl;
return 0;
case 'h':
return help(0);
}
}
return help(1);
}
private:
struct Cmp {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef utils_h_
#define utils_h_

#include <string>
#include <cstring>

#ifndef SIZEOF_BITS
#define SIZEOF_BITS(x) (8 * sizeof(x))
Expand Down

0 comments on commit c8e30fa

Please sign in to comment.