From 0e47d992182ba1899a6431f0e0548ad60e626a91 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 13 Mar 2012 14:06:10 +0000 Subject: [PATCH] tweaks to command line --- thin_check.cc | 20 ++++++++++---------- thin_dump.cc | 22 +++++++++++----------- thin_restore.cc | 23 +++++++++++++---------- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/thin_check.cc b/thin_check.cc index c3408b4..104c8b8 100644 --- a/thin_check.cc +++ b/thin_check.cc @@ -48,12 +48,12 @@ namespace { return 0; } - void usage(string const &cmd) { - cerr << "Usage: " << cmd << " [options] {device|file}" << endl - << "Options:" << endl - << " {-q|--quiet}" << endl - << " {-h|--help}" << endl - << " {-V|--version}" << endl; + void usage(ostream &out, string const &cmd) { + out << "Usage: " << cmd << " [options] {device|file}" << endl + << "Options:" << endl + << " {-q|--quiet}" << endl + << " {-h|--help}" << endl + << " {-V|--version}" << endl; } } @@ -72,7 +72,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': - usage(basename(argv[0])); + usage(cout, basename(argv[0])); return 0; case 'q': @@ -84,14 +84,14 @@ int main(int argc, char **argv) return 0; default: - usage(basename(argv[0])); + usage(cerr, basename(argv[0])); return 1; } } if (argc == optind) { - cerr << "No output file provided." << endl; - usage(basename(argv[0])); + cerr << "No input file provided." << endl; + usage(cerr, basename(argv[0])); exit(1); } diff --git a/thin_dump.cc b/thin_dump.cc index 68f6a2c..5980e2c 100644 --- a/thin_dump.cc +++ b/thin_dump.cc @@ -54,13 +54,13 @@ namespace { return 0; } - void usage(string const &cmd) { - cerr << "Usage: " << cmd << " [options] {device|file}" << endl << endl - << "Options:" << endl - << " {-h|--help}" << endl - << " {-f|--format} {xml|human_readable}" << endl - << " {-r|--repair}" << endl - << " {-V|--version}" << endl; + void usage(ostream &out, string const &cmd) { + out << "Usage: " << cmd << " [options] {device|file}" << endl + << "Options:" << endl + << " {-h|--help}" << endl + << " {-f|--format} {xml|human_readable}" << endl + << " {-r|--repair}" << endl + << " {-V|--version}" << endl; } } @@ -81,7 +81,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': - usage(basename(argv[0])); + usage(cout, basename(argv[0])); return 0; case 'f': @@ -97,14 +97,14 @@ int main(int argc, char **argv) return 0; default: - usage(basename(argv[0])); + usage(cerr, basename(argv[0])); return 1; } } if (argc == optind) { - cerr << "No output file provided." << endl; - usage(basename(argv[0])); + cerr << "No input file provided." << endl; + usage(cerr, basename(argv[0])); return 1; } diff --git a/thin_restore.cc b/thin_restore.cc index 4086910..a3ff53f 100644 --- a/thin_restore.cc +++ b/thin_restore.cc @@ -40,6 +40,7 @@ using namespace thin_provisioning; namespace { int restore(string const &backup_file, string const &dev) { try { + // The block size gets updated by the restorer. metadata::ptr md(new metadata(dev, metadata::CREATE, 128, 0)); emitter::ptr restorer = create_restore_emitter(md); ifstream in(backup_file.c_str(), ifstream::in); @@ -53,13 +54,13 @@ namespace { return 0; } - void usage(string const &cmd) { - cerr << "Usage: " << cmd << " [options]" << endl << endl; - cerr << "Options:" << endl; - cerr << " {-h|--help}" << endl; - cerr << " {-i|--input} input_file" << endl; - cerr << " {-o|--output} {device|file}" << endl; - cerr << " {-V|--version}" << endl; + void usage(ostream &out, string const &cmd) { + out << "Usage: " << cmd << " [options]" << endl + << "Options:" << endl + << " {-h|--help}" << endl + << " {-i|--input} input_file" << endl + << " {-o|--output} {device|file}" << endl + << " {-V|--version}" << endl; } } @@ -79,7 +80,7 @@ int main(int argc, char **argv) while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch(c) { case 'h': - usage(basename(argv[0])); + usage(cout, basename(argv[0])); return 0; case 'i': @@ -95,23 +96,25 @@ int main(int argc, char **argv) return 0; default: - usage(basename(argv[0])); + usage(cerr, basename(argv[0])); return 1; } } if (argc != optind) { - usage(basename(argv[0])); + usage(cerr, basename(argv[0])); return 1; } if (input.empty()) { cerr << "No input file provided." << endl; + usage(cerr, basename(argv[0])); return 1; } if (output.empty()) { cerr << "No output file provided." << endl; + usage(cerr, basename(argv[0])); return 1; }