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,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);
}

View File

@ -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;
}

View File

@ -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;
}