[base] introduce a command type that gets registered with the app
This commit is contained in:
@@ -33,18 +33,28 @@ namespace {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void usage(ostream &out, string const &cmd) {
|
||||
out << "Usage: " << cmd << " [options] {device|file}" << endl
|
||||
<< "Options:" << endl
|
||||
<< " {-h|--help}" << endl
|
||||
<< " {-i|--input} <input metadata (binary format)>" << endl
|
||||
<< " {-o|--output} <output metadata (binary format)>" << endl
|
||||
<< " {-V|--version}" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int thin_repair_main(int argc, char **argv)
|
||||
//----------------------------------------------------------------
|
||||
|
||||
thin_repair_cmd::thin_repair_cmd()
|
||||
: command("thin_repair")
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
thin_repair_cmd::usage(std::ostream &out) const
|
||||
{
|
||||
out << "Usage: " << get_name() << " [options] {device|file}" << endl
|
||||
<< "Options:" << endl
|
||||
<< " {-h|--help}" << endl
|
||||
<< " {-i|--input} <input metadata (binary format)>" << endl
|
||||
<< " {-o|--output} <output metadata (binary format)>" << endl
|
||||
<< " {-V|--version}" << endl;
|
||||
}
|
||||
|
||||
int
|
||||
thin_repair_cmd::run(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
boost::optional<string> input_path, output_path;
|
||||
@@ -61,7 +71,7 @@ int thin_repair_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 'i':
|
||||
@@ -77,26 +87,24 @@ int thin_repair_main(int argc, char **argv)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
usage(cerr, basename(argv[0]));
|
||||
usage(cerr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!input_path) {
|
||||
cerr << "no input file provided" << endl;
|
||||
usage(cerr, basename(argv[0]));
|
||||
usage(cerr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!output_path) {
|
||||
cerr << "no output file provided" << endl;
|
||||
usage(cerr, basename(argv[0]));
|
||||
usage(cerr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return repair(*input_path, *output_path);
|
||||
}
|
||||
|
||||
base::command thin_provisioning::thin_repair_cmd("thin_repair", thin_repair_main);
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user