From af1af617352d248fbe32d12b0fe15924aba45a1c Mon Sep 17 00:00:00 2001 From: Heinz Mauelshagen Date: Mon, 5 Mar 2012 19:34:05 +0100 Subject: [PATCH] Fix some command line options [Milan] --- thin_check.cc | 8 ++++++-- thin_dump.cc | 29 +++++++++-------------------- thin_restore.cc | 14 ++++++-------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/thin_check.cc b/thin_check.cc index 9db11bb..fdc09d6 100644 --- a/thin_check.cc +++ b/thin_check.cc @@ -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); } diff --git a/thin_dump.cc b/thin_dump.cc index 0d11915..3189178 100644 --- a/thin_dump.cc +++ b/thin_dump.cc @@ -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); } - -//---------------------------------------------------------------- diff --git a/thin_restore.cc b/thin_restore.cc index 4ec2409..a3ce23b 100644 --- a/thin_restore.cc +++ b/thin_restore.cc @@ -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); - } - -//----------------------------------------------------------------