[base] introduce a command type that gets registered with the app
This commit is contained in:
@@ -111,22 +111,30 @@ namespace {
|
||||
|
||||
return region(begin, end);
|
||||
};
|
||||
|
||||
void usage(ostream &out, string const &cmd) {
|
||||
out << "Usage: " << cmd << " [options] {device|file}" << endl
|
||||
<< "Options:" << endl
|
||||
<< " {-h|--help}" << endl
|
||||
<< " {-V|--version}" << endl
|
||||
<< " {--region <block range>}*" << endl
|
||||
<< "Where:" << endl
|
||||
<< " <block range> is of the form <begin>..<one-past-the-end>" << endl
|
||||
<< " for example 5..45 denotes blocks 5 to 44 inclusive, but not block 45" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
int thin_rmap_main(int argc, char **argv)
|
||||
thin_rmap_cmd::thin_rmap_cmd()
|
||||
: command("thin_rmap")
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
thin_rmap_cmd::usage(std::ostream &out) const
|
||||
{
|
||||
out << "Usage: " << get_name() << " [options] {device|file}" << endl
|
||||
<< "Options:" << endl
|
||||
<< " {-h|--help}" << endl
|
||||
<< " {-V|--version}" << endl
|
||||
<< " {--region <block range>}*" << endl
|
||||
<< "Where:" << endl
|
||||
<< " <block range> is of the form <begin>..<one-past-the-end>" << endl
|
||||
<< " for example 5..45 denotes blocks 5 to 44 inclusive, but not block 45" << endl;
|
||||
}
|
||||
|
||||
int
|
||||
thin_rmap_cmd::run(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
vector<region> regions;
|
||||
@@ -141,7 +149,7 @@ int thin_rmap_main(int argc, char **argv)
|
||||
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage(cout, basename(argv[0]));
|
||||
usage(cout);
|
||||
return 0;
|
||||
|
||||
case 'V':
|
||||
@@ -161,20 +169,18 @@ int thin_rmap_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return rmap(argv[optind], regions);
|
||||
}
|
||||
|
||||
base::command thin_provisioning::thin_rmap_cmd("thin_rmap", thin_rmap_main);
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user