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

View File

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