[thini_restore] add a quiet option to turn off the progress monitor

This commit is contained in:
Joe Thornber 2014-08-05 12:10:34 +01:00
parent fccc1dfcb0
commit d00aef9219
2 changed files with 15 additions and 6 deletions

View File

@ -17,6 +17,7 @@ Feature: thin_restore
{-h|--help} {-h|--help}
{-i|--input} <input xml file> {-i|--input} <input xml file>
{-o|--output} <output device or file> {-o|--output} <output device or file>
{-q|--quiet}
{-V|--version} {-V|--version}
""" """
@ -30,6 +31,7 @@ Feature: thin_restore
{-h|--help} {-h|--help}
{-i|--input} <input xml file> {-i|--input} <input xml file>
{-o|--output} <output device or file> {-o|--output} <output device or file>
{-q|--quiet}
{-V|--version} {-V|--version}
""" """

View File

@ -52,14 +52,14 @@ namespace {
return info.st_size; return info.st_size;
} }
progress_monitor::ptr create_monitor() { progress_monitor::ptr create_monitor(bool quiet) {
if (isatty(fileno(stdout))) if (!quiet && isatty(fileno(stdout)))
return create_progress_bar("Restoring"); return create_progress_bar("Restoring");
else else
return create_quiet_progress_monitor(); return create_quiet_progress_monitor();
} }
int restore(string const &backup_file, string const &dev) { int restore(string const &backup_file, string const &dev, bool quiet) {
try { try {
// The block size gets updated by the restorer. // 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));
@ -68,7 +68,7 @@ namespace {
check_file_exists(backup_file); check_file_exists(backup_file);
ifstream in(backup_file.c_str(), ifstream::in); ifstream in(backup_file.c_str(), ifstream::in);
progress_monitor::ptr monitor = create_monitor(); progress_monitor::ptr monitor = create_monitor(quiet);
parse_xml(in, restorer, get_file_length(backup_file), monitor); parse_xml(in, restorer, get_file_length(backup_file), monitor);
} catch (std::exception &e) { } catch (std::exception &e) {
@ -85,6 +85,7 @@ namespace {
<< " {-h|--help}" << endl << " {-h|--help}" << endl
<< " {-i|--input} <input xml file>" << endl << " {-i|--input} <input xml file>" << endl
<< " {-o|--output} <output device or file>" << endl << " {-o|--output} <output device or file>" << endl
<< " {-q|--quiet}" << endl
<< " {-V|--version}" << endl; << " {-V|--version}" << endl;
} }
} }
@ -93,12 +94,14 @@ int main(int argc, char **argv)
{ {
int c; int c;
char const *prog_name = basename(argv[0]); char const *prog_name = basename(argv[0]);
const char *shortopts = "hi:o:V"; const char *shortopts = "hi:o:qV";
string input, output; string input, output;
bool quiet = false;
const struct option longopts[] = { const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h'},
{ "input", required_argument, NULL, 'i' }, { "input", required_argument, NULL, 'i' },
{ "output", required_argument, NULL, 'o'}, { "output", required_argument, NULL, 'o'},
{ "quiet", no_argument, NULL, 'q'},
{ "version", no_argument, NULL, 'V'}, { "version", no_argument, NULL, 'V'},
{ NULL, no_argument, NULL, 0 } { NULL, no_argument, NULL, 0 }
}; };
@ -117,6 +120,10 @@ int main(int argc, char **argv)
output = optarg; output = optarg;
break; break;
case 'q':
quiet = true;
break;
case 'V': case 'V':
cout << THIN_PROVISIONING_TOOLS_VERSION << endl; cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
return 0; return 0;
@ -144,7 +151,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
return restore(input, output); return restore(input, output, quiet);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------