tweaks to command line

This commit is contained in:
Joe Thornber 2012-03-13 14:06:10 +00:00
parent 4a1484330d
commit 0e47d99218
3 changed files with 34 additions and 31 deletions

View File

@ -48,8 +48,8 @@ namespace {
return 0; return 0;
} }
void usage(string const &cmd) { void usage(ostream &out, string const &cmd) {
cerr << "Usage: " << cmd << " [options] {device|file}" << endl out << "Usage: " << cmd << " [options] {device|file}" << endl
<< "Options:" << endl << "Options:" << endl
<< " {-q|--quiet}" << endl << " {-q|--quiet}" << endl
<< " {-h|--help}" << endl << " {-h|--help}" << endl
@ -72,7 +72,7 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':
usage(basename(argv[0])); usage(cout, basename(argv[0]));
return 0; return 0;
case 'q': case 'q':
@ -84,14 +84,14 @@ int main(int argc, char **argv)
return 0; return 0;
default: default:
usage(basename(argv[0])); usage(cerr, basename(argv[0]));
return 1; return 1;
} }
} }
if (argc == optind) { if (argc == optind) {
cerr << "No output file provided." << endl; cerr << "No input file provided." << endl;
usage(basename(argv[0])); usage(cerr, basename(argv[0]));
exit(1); exit(1);
} }

View File

@ -54,8 +54,8 @@ namespace {
return 0; return 0;
} }
void usage(string const &cmd) { void usage(ostream &out, string const &cmd) {
cerr << "Usage: " << cmd << " [options] {device|file}" << endl << endl out << "Usage: " << cmd << " [options] {device|file}" << endl
<< "Options:" << endl << "Options:" << endl
<< " {-h|--help}" << endl << " {-h|--help}" << endl
<< " {-f|--format} {xml|human_readable}" << endl << " {-f|--format} {xml|human_readable}" << endl
@ -81,7 +81,7 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':
usage(basename(argv[0])); usage(cout, basename(argv[0]));
return 0; return 0;
case 'f': case 'f':
@ -97,14 +97,14 @@ int main(int argc, char **argv)
return 0; return 0;
default: default:
usage(basename(argv[0])); usage(cerr, basename(argv[0]));
return 1; return 1;
} }
} }
if (argc == optind) { if (argc == optind) {
cerr << "No output file provided." << endl; cerr << "No input file provided." << endl;
usage(basename(argv[0])); usage(cerr, basename(argv[0]));
return 1; return 1;
} }

View File

@ -40,6 +40,7 @@ using namespace thin_provisioning;
namespace { namespace {
int restore(string const &backup_file, string const &dev) { int restore(string const &backup_file, string const &dev) {
try { try {
// The block size gets updated by the restorer.
metadata::ptr md(new metadata(dev, metadata::CREATE, 128, 0)); metadata::ptr md(new metadata(dev, metadata::CREATE, 128, 0));
emitter::ptr restorer = create_restore_emitter(md); emitter::ptr restorer = create_restore_emitter(md);
ifstream in(backup_file.c_str(), ifstream::in); ifstream in(backup_file.c_str(), ifstream::in);
@ -53,13 +54,13 @@ namespace {
return 0; return 0;
} }
void usage(string const &cmd) { void usage(ostream &out, string const &cmd) {
cerr << "Usage: " << cmd << " [options]" << endl << endl; out << "Usage: " << cmd << " [options]" << endl
cerr << "Options:" << endl; << "Options:" << endl
cerr << " {-h|--help}" << endl; << " {-h|--help}" << endl
cerr << " {-i|--input} input_file" << endl; << " {-i|--input} input_file" << endl
cerr << " {-o|--output} {device|file}" << endl; << " {-o|--output} {device|file}" << endl
cerr << " {-V|--version}" << endl; << " {-V|--version}" << endl;
} }
} }
@ -79,7 +80,7 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
switch(c) { switch(c) {
case 'h': case 'h':
usage(basename(argv[0])); usage(cout, basename(argv[0]));
return 0; return 0;
case 'i': case 'i':
@ -95,23 +96,25 @@ int main(int argc, char **argv)
return 0; return 0;
default: default:
usage(basename(argv[0])); usage(cerr, basename(argv[0]));
return 1; return 1;
} }
} }
if (argc != optind) { if (argc != optind) {
usage(basename(argv[0])); usage(cerr, basename(argv[0]));
return 1; return 1;
} }
if (input.empty()) { if (input.empty()) {
cerr << "No input file provided." << endl; cerr << "No input file provided." << endl;
usage(cerr, basename(argv[0]));
return 1; return 1;
} }
if (output.empty()) { if (output.empty()) {
cerr << "No output file provided." << endl; cerr << "No output file provided." << endl;
usage(cerr, basename(argv[0]));
return 1; return 1;
} }