From d00aef9219aa6f7a8b7f240b338649868a872a89 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 5 Aug 2014 12:10:34 +0100 Subject: [PATCH] [thini_restore] add a quiet option to turn off the progress monitor --- features/thin_restore.feature | 2 ++ thin-provisioning/thin_restore.cc | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/features/thin_restore.feature b/features/thin_restore.feature index d02ebb0..7f5b5be 100644 --- a/features/thin_restore.feature +++ b/features/thin_restore.feature @@ -17,6 +17,7 @@ Feature: thin_restore {-h|--help} {-i|--input} {-o|--output} + {-q|--quiet} {-V|--version} """ @@ -30,6 +31,7 @@ Feature: thin_restore {-h|--help} {-i|--input} {-o|--output} + {-q|--quiet} {-V|--version} """ diff --git a/thin-provisioning/thin_restore.cc b/thin-provisioning/thin_restore.cc index 86c7801..d82eae1 100644 --- a/thin-provisioning/thin_restore.cc +++ b/thin-provisioning/thin_restore.cc @@ -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} " << endl << " {-o|--output} " << 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); } //----------------------------------------------------------------