Fix some command line options [Milan]

This commit is contained in:
Heinz Mauelshagen 2012-03-05 19:34:05 +01:00
parent 8f0a868554
commit af1af61735
3 changed files with 21 additions and 30 deletions

View File

@ -49,7 +49,7 @@ namespace {
}
void usage(string const &cmd) {
cerr << "Usage: " << cmd << " {device|file}" << endl
cerr << "Usage: " << cmd << " [options] {device|file}" << endl
<< "Options:" << endl
<< " {-q|--quiet}" << endl
<< " {-h|--help}" << endl
@ -82,10 +82,14 @@ int main(int argc, char **argv)
case 'V':
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
return 0;
default:
usage(basename(argv[0]));
return 1;
}
}
if (argc == 1) {
if (argc == optind) {
cerr << "No output file provided." << endl;
usage(basename(argv[0]));
exit(1);
}

View File

@ -30,8 +30,6 @@ using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;
//----------------------------------------------------------------
namespace {
int dump(string const &path, string const &format, bool repair) {
try {
@ -49,7 +47,7 @@ namespace {
metadata_dump(md, e, repair);
} catch (std::exception &e) {
cerr << e.what();
cerr << e.what() << endl;
return 1;
}
@ -61,7 +59,6 @@ namespace {
<< "Options:" << endl
<< " {-h|--help}" << endl
<< " {-f|--format} {xml|human_readable}" << endl
<< " {-i|--input} {xml|human_readable} input_file" << endl
<< " {-r|--repair}" << endl
<< " {-V|--version}" << endl;
}
@ -71,12 +68,11 @@ int main(int argc, char **argv)
{
int c;
bool repair = false;
const char shortopts[] = "hf:i:rV";
string filename, format = "xml";
const char shortopts[] = "hf:rV";
string format = "xml";
const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'},
{ "format", required_argument, NULL, 'f' },
{ "input", required_argument, NULL, 'i'},
{ "repair", no_argument, NULL, 'r'},
{ "version", no_argument, NULL, 'V'},
{ NULL, no_argument, NULL, 0 }
@ -92,10 +88,6 @@ int main(int argc, char **argv)
format = optarg;
break;
case 'i':
filename = optarg;
break;
case 'r':
repair = true;
break;
@ -103,20 +95,17 @@ int main(int argc, char **argv)
case 'V':
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
return 0;
default:
usage(basename(argv[0]));
return 1;
}
}
if (argc == 1) {
if (argc == optind) {
cerr << "No output file provided." << endl;
usage(basename(argv[0]));
return 1;
}
if (filename.empty()) {
cerr << "No output file provided." << endl;
return 1;
}
return dump(filename, format, repair);
return dump(argv[optind], format, repair);
}
//----------------------------------------------------------------

View File

@ -37,8 +37,6 @@ using namespace persistent_data;
using namespace std;
using namespace thin_provisioning;
//----------------------------------------------------------------
namespace {
int restore(string const &backup_file, string const &dev) {
try {
@ -48,7 +46,7 @@ namespace {
parse_xml(in, restorer);
} catch (std::exception &e) {
cerr << e.what();
cerr << e.what() << endl;
return 1;
}
@ -60,7 +58,7 @@ namespace {
cerr << "Options:" << endl;
cerr << " {-h|--help}" << endl;
cerr << " {-i|--input} input_file" << endl;
cerr << " {-o [ --output} {device|file}" << endl;
cerr << " {-o|--output} {device|file}" << endl;
cerr << " {-V|--version}" << endl;
}
}
@ -92,10 +90,13 @@ int main(int argc, char **argv)
case 'V':
cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
return 0;
default:
usage(basename(argv[0]));
return 1;
}
}
if (argc == 1) {
if (argc != optind) {
usage(basename(argv[0]));
return 1;
}
@ -111,7 +112,4 @@ int main(int argc, char **argv)
}
return restore(input, output);
}
//----------------------------------------------------------------