[base] introduce a command type that gets registered with the app

This commit is contained in:
Joe Thornber
2016-01-08 12:51:52 +00:00
parent a709b9718b
commit c93e728ef4
28 changed files with 776 additions and 411 deletions

View File

@ -54,20 +54,28 @@ namespace {
return 0;
}
void usage(ostream &out, string const &cmd) {
out << "Usage: " << cmd << " [options] {device|file}" << endl
<< "Options:" << endl
<< " {-h|--help}" << endl
<< " {-o <xml file>}" << endl
<< " {-V|--version}" << endl
<< " {--repair}" << endl;
}
}
//----------------------------------------------------------------
int cache_dump_main(int argc, char **argv)
cache_dump_cmd::cache_dump_cmd()
: command("cache_dump")
{
}
void
cache_dump_cmd::usage(std::ostream &out) const
{
out << "Usage: " << get_name() << " [options] {device|file}" << endl
<< "Options:" << endl
<< " {-h|--help}" << endl
<< " {-o <xml file>}" << endl
<< " {-V|--version}" << endl
<< " {--repair}" << endl;
}
int
cache_dump_cmd::run(int argc, char **argv)
{
int c;
flags fs;
@ -89,7 +97,7 @@ int cache_dump_main(int argc, char **argv)
break;
case 'h':
usage(cout, basename(argv[0]));
usage(cout);
return 0;
case 'o':
@ -101,20 +109,18 @@ int cache_dump_main(int argc, char **argv)
return 0;
default:
usage(cerr, basename(argv[0]));
usage(cerr);
return 1;
}
}
if (argc == optind) {
cerr << "No input file provided." << endl;
usage(cerr, basename(argv[0]));
usage(cerr);
return 1;
}
return dump(argv[optind], output, fs);
}
base::command caching::cache_dump_cmd("cache_dump", cache_dump_main);
//----------------------------------------------------------------