From: Jan Kupec Date: Thu, 5 Jul 2007 21:07:54 +0000 (+0000) Subject: --silent global option added. Use cout_n for normal program X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~303 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98b963f2a3f99975a2994c6360246ece99ff821e;p=platform%2Fupstream%2Fzypper.git --silent global option added. Use cout_n for normal program output which should be suppressed by --silent option. - some output clean-up (still work to do) --- diff --git a/doc/TODO b/doc/TODO index eb5c7e8..ead34f8 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,8 +1,16 @@ -TODO +0.9.0 + +- implement all rug commands (where it has sense) +- clean up and improve output, add --silent mode, sort normal, verbose + and debug output. +- refresh - show progress on default output, verbose progress with -v + + +NOT SCHEDULED +------------- General -- implement all rug commands, if only to say: Not implemented (yet) - script progress: does the output contain newline?? - installation and deletion notifications - --dry-run (use ZYppCommitPolicy.h) @@ -15,7 +23,7 @@ Patches (svn up ncurses) - reboot-needed: ? - cron updater: --- wrapper script for restart-packager +- wrapper script for restart-packager - zypper patch-search (for rug compatibility) Packages diff --git a/doc/zypper.8 b/doc/zypper.8 index c57638b..0ed3b88 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -234,6 +234,9 @@ Print zypper version number and exit. .I \-v, \-\-verbose Increase verbosity. For debugging output specify this option twice. .TP +.I \-S, \-\-silent +Suppress normal output. Brief error messages will still be printed on standard error output. If used together with conflicting --verbose option, the --verbose option takes preference. +.TP .I \-t, \-\-terse Terse output for machine consumption. .TP diff --git a/package/zypper.changes b/package/zypper.changes index bd8286c..50c6c07 100644 --- a/package/zypper.changes +++ b/package/zypper.changes @@ -1,4 +1,12 @@ ------------------------------------------------------------------- +Thu Jul 5 23:06:49 CEST 2007 - jkupec@suse.cz + +- --silent global option added. Use cout_n for normal program + output which should be suppressed by --silent option. +- some output clean-up (still work to do) +- r5898 + +------------------------------------------------------------------- Tue Jul 3 13:34:09 CEST 2007 - jkupec@suse.cz - adapted to refactored libzypp repository management diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index 9e60bb3..4cec179 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -20,9 +20,11 @@ void display_done () { //template //Action ... int read_action_ari (int default_action) { - cout << _("(A)bort, (R)etry, (I)gnore?") << " "; // don't translate letters in parentheses!! + if (gSettings.verbosity >= 0 || !gSettings.non_interactive) + // TranslatorExplanation don't translate letters in parentheses!! + cout << _("(A)bort, (R)etry, (I)gnore?") << " "; - // abort if no default has been specified + // choose abort if no default has been specified if (default_action == -1) { default_action = 0; } @@ -37,7 +39,7 @@ int read_action_ari (int default_action) { default: c = '?'; } // print the answer for conveniecne - cout << c << endl; + cout_n << c << endl; return default_action; } @@ -53,7 +55,7 @@ int read_action_ari (int default_action) { return 1; else if (c == 'i') return 2; - cout << "?" << endl; + cerr << _("Invalid answer. Choose letter a, r, or i.") << endl; } return default_action; diff --git a/src/zypper-info.cc b/src/zypper-info.cc index 43a9184..27b4fd0 100644 --- a/src/zypper-info.cc +++ b/src/zypper-info.cc @@ -81,7 +81,8 @@ Copy and modify /usr/share/vim/current/gvimrc to ~/.gvimrc if needed. */ void printPkgInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item) { - cout << _("Catalog: ") << pool_item.resolvable()->repository().info().alias() << endl; + cout << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: ")) + << pool_item.resolvable()->repository().info().alias() << endl; cout << _("Name: ") << pool_item.resolvable()->name() << endl; cout << _("Version: ") << pool_item.resolvable()->edition().asString() << endl; cout << _("Arch: ") << pool_item.resolvable()->arch().asString() << endl; @@ -101,7 +102,6 @@ void printPkgInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item) { cout << _("Installed Size: ") << pool_item.resolvable()->size().asString() << endl; cout << _("Summary: ") << pool_item.resolvable()->summary() << endl; cout << _("Description: ") << endl; - cout << pool_item.resolvable()->description() << endl; } diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index 53b0fb6..e896cbf 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -150,28 +150,32 @@ void mark_for_install( const ResObject::Kind &kind, // name and kind match: ProvideProcess installer (God->architecture(), "" /*version*/); - cerr_vv << "Iterating over [" << kind << "]" << name << endl; + cout_vv << "Iterating over [" << kind << "]" << name << endl; invokeOnEach( pool.byNameBegin( name ), pool.byNameEnd( name ), resfilter::ByKind( kind ), zypp::functor::functorRef (installer) ); - cerr_vv << "... done" << endl; + cout_vv << "... done" << endl; if (!installer.item) { - cerr << kind << " '" << name << "' " << _("not found") << endl; - return; //error? + // TranslatorExplanation e.g. "package 'pornview' not found" + cerr << format(_("%s '%s' not found")) % kind % name << endl; + WAR << format("%s '%s' not found") % kind % name << endl; + + return; } if (installer.installed_item && installer.installed_item.resolvable()->edition() == installer.item.resolvable()->edition() && installer.installed_item.resolvable()->arch() == installer.item.resolvable()->arch()) { - cout << _("skipping ") << kind.asString() << " '" << name << "' " << _("(already installed)") << endl; + cout_n << _("skipping ") << kind.asString() << " '" << name << "' " << _("(already installed)") << endl; } else { // TODO don't use setToBeInstalled for this purpose but higher level solver API bool result = installer.item.status().setToBeInstalled( zypp::ResStatus::USER ); if (!result) { cerr << format(_("Failed to add '%s' to the list of packages to be installed.")) % name << endl; + ERR << "Could not set " << name << " as to-be-installed" << endl; } } } @@ -186,10 +190,14 @@ struct DeleteProcess bool operator() ( const PoolItem& provider ) { found = true; - cerr_vv << "Marking for deletion: " << provider << endl; + cout_vv << "Marking for deletion: " << provider << endl; bool result = provider.status().setToBeUninstalled( zypp::ResStatus::USER ); if (!result) { - cerr << _("Failed") << endl; + cerr << format( + _("Failed to add '%s' to the list of packages to be removed.")) + % provider.resolvable()->name() << endl; + ERR << "Could not set " << provider.resolvable()->name() + << " as to-be-uninstalled" << endl; } return true; // get all of them } @@ -449,9 +457,15 @@ void load_repo_resolvables() void load_target_resolvables() { - cout << _("Reading RPM database...") << endl; + cout_n << _("Reading RPM database..."); + MIL << "Going to read RPM database" << endl; + ResStore tgt_resolvables(God->target()->resolvables()); - cout_v << " " << format(_("%s resolvables.")) % tgt_resolvables.size() << endl; + + cout_v << " " << format(_("(%s resolvables)")) % tgt_resolvables.size(); + cout_n << endl; + DBG << tgt_resolvables.size() << " resolvables read"; + God->addResolvables(tgt_resolvables, true /*installed*/); } @@ -560,7 +574,12 @@ void show_patches() tbl << tr; } tbl.sort (1); // Name - cout << tbl; + + if (tbl.empty()) + cout_n << _("No needed patches found.") << endl; + else + // display the result, even if --silent specified + cout << tbl; } // ---------------------------------------------------------------------------- @@ -616,7 +635,7 @@ void list_patch_updates () tbl.sort (1); // Name if (tbl.empty()) - cout << _("No updates found.") << endl; + cout_n << _("No updates found.") << endl; else cout << tbl; } @@ -737,7 +756,7 @@ void list_updates( const ResObject::Kind &kind ) tbl.sort (gSettings.is_rug_compatible? 3: 2); // Name if (tbl.empty()) - cout << _("No updates found.") << endl; + cout_n << _("No updates found.") << endl; else cout << tbl; } diff --git a/src/zypper-rpm-callbacks.h b/src/zypper-rpm-callbacks.h index 67e8ba1..8e04fe5 100644 --- a/src/zypper-rpm-callbacks.h +++ b/src/zypper-rpm-callbacks.h @@ -13,6 +13,8 @@ #include #include +#include + #include #include #include @@ -33,13 +35,12 @@ struct MessageResolvableReportReceiver : public zypp::callback::ReceiveReporttext() << endl; - // TODO in interactive mode, wait for ENTER? + cout_v << message << endl; // [message]important-msg-1.0-1 + cout_n << message->text() << endl; + //! \todo in interactive mode, wait for ENTER? } }; -#ifndef LIBZYPP_1xx ostream& operator<< (ostream& stm, zypp::target::ScriptResolvableReport::Task task) { return stm << (task==zypp::target::ScriptResolvableReport::DO? "DO": "UNDO"); } @@ -51,8 +52,9 @@ struct ScriptResolvableReportReceiver : public zypp::callback::ReceiveReport @@ -129,7 +130,8 @@ struct RemoveResolvableReportReceiver : public zypp::callback::ReceiveReportname() % resolvable->edition() << endl; } virtual bool progress(int value, zypp::Resolvable::constPtr resolvable) diff --git a/src/zypper-source-callbacks.h b/src/zypper-source-callbacks.h index 1a5d58a..6758098 100644 --- a/src/zypper-source-callbacks.h +++ b/src/zypper-source-callbacks.h @@ -21,6 +21,7 @@ #include #include +#include "zypper.h" #include "zypper-callbacks.h" /////////////////////////////////////////////////////////////////// @@ -90,8 +91,8 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport (resolvable_ptr); zypp::Package::constPtr ro = zypp::asKind (resolvable_ptr); if (ro) { - std::cerr << ", " << ro->archivesize () + cout_n << ", " << ro->archivesize () << "(" << ro->size () << " unpacked)"; } - std::cerr << std::endl; + cout_n << std::endl; } // return false if the download should be aborted right now diff --git a/src/zypper-sources.cc b/src/zypper-sources.cc index 71186f2..71b471e 100644 --- a/src/zypper-sources.cc +++ b/src/zypper-sources.cc @@ -44,7 +44,7 @@ static void do_init_repos() if (do_refresh) { //! \todo progress reporting - cout << "Refreshing " << repo.alias() << endl; + cout_n << "Refreshing " << repo.alias() << endl; manager.refreshMetadata(repo); } } @@ -115,7 +115,13 @@ static void print_repo_list( const std::list &repos ) tbl << tr; } - cout << tbl; + + if (tbl.empty()) + cout_n << _("No repositories defined." + " Use 'zypper addrepo' command to add one or more repositories.") + << endl; + else + cout << tbl; } // ---------------------------------------------------------------------------- @@ -131,8 +137,9 @@ void list_repos() } catch ( const Exception &e ) { - cerr << _("Error reading system sources: ") << endl - << e.msg() << endl; + ZYPP_CAUGHT(e); + cerr << _("Error reading system sources:") << endl + << e.asUserString() << endl; exit(ZYPPER_EXIT_ERR_ZYPP); } @@ -161,26 +168,29 @@ void refresh_repos() try { - cout << _("Refreshing ") << it->alias() << endl; - //<< "URI: " << it->url() << endl; + cout_n << _("Refreshing ") << it->alias() << endl; + manager.refreshMetadata(repo); //! \todo progress reporting - manager.refreshMetadata(repo); cout_v << _("Creating repository cache...") << endl; manager.buildCache(repo); - cout << _("DONE") << endl << endl; + cout_n << _("DONE") << endl << endl; } catch ( const Exception &e ) { - cerr << format(_("Error reading repository '%s':")) % repo.alias() << endl - << e.msg() << endl; + cerr << format(_("Error reading repository '%s':")) % repo.alias() + << endl << e.msg() << endl; cerr << format(_("Skipping repository '%s' because of the above error.")) - % repo.alias() - << endl; + % repo.alias() << endl; + // log untranslated message + ERR << format("Error reading repository '%s':") % repo.alias() + << endl << e.msg() << endl; + ERR << format("Skipping repository '%s' because of the above error.") + % repo.alias() << endl; } } - cout << _("All system sources have been refreshed.") << endl; + cout_n << _("All system sources have been refreshed.") << endl; } // ---------------------------------------------------------------------------- @@ -211,6 +221,7 @@ int add_repo(const RepoInfo & repo) RepoManager manager; cout_v << format(_("Adding repository '%s'.")) % repo.alias() << endl; + MIL << "Going to add repository: " << repo << endl; try { @@ -218,32 +229,35 @@ int add_repo(const RepoInfo & repo) } catch (const MediaException & e) { - cerr << "Problem transfering repository data for reading." << endl; + cerr << _("Problem transfering repository data from specified URL.") << endl; + ERR << "Problem transfering repository data from specified URL." << endl; return ZYPPER_EXIT_ERR_ZYPP; } catch (const ParseException & e) { - cerr << "Problem while reading repository data." << endl; + cerr << _("Problem parsing repository data.") << endl; + ERR << "Problem parsing repository data." << endl; return ZYPPER_EXIT_ERR_ZYPP; } catch (const RepoAlreadyExistsException & e) { - string message = _( - "A repository named '%s'." - " already exists."); - cerr << format(message) % repo.alias() << endl; + cerr << format("Repository named '%s' already exists.") % repo.alias() << endl; + ERR << "Repository named '%s' already exists." << endl; return ZYPPER_EXIT_ERR_ZYPP; } catch (const Exception & e) { - cerr << e.msg() << endl; + ZYPP_CAUGHT(e); + cerr << e.asUserString() << endl; return ZYPPER_EXIT_ERR_BUG; } - cout << format(_("Repository '%s' successfully added:")) % repo.alias() << endl; - cout << ( repo.enabled() ? "[x]" : "[ ]" ); - cout << ( repo.autorefresh() ? "* " : " " ); - cout << repo.alias() << " (" << *repo.baseUrlsBegin() << ")" << endl; + cout_n << format(_("Repository '%s' successfully added:")) % repo.alias() << endl; + cout_n << ( repo.enabled() ? "[x]" : "[ ]" ); + cout_n << ( repo.autorefresh() ? "* " : " " ); + cout_n << repo.alias() << " (" << *repo.baseUrlsBegin() << ")" << endl; + + MIL << "Repository successfully added: " << repo << endl; return ZYPPER_EXIT_OK; } @@ -276,16 +290,23 @@ int add_repo_by_url( const zypp::Url & url, const string & alias, cerr << format(_( "Warning! Overriding detected repository type '%s' with " "manually specified '%s'.")) % repotype_probed % repotype - << endl; + << endl; + WAR << format( + "Overriding detected repository type '%s' with " + "manually specified '%s'.") % repotype_probed % repotype + << endl; } } catch (RepoUnknownTypeException & e) { string message = _( - "Warning: Unknown repository type '%s'." + "Unknown repository type '%s'." " Using detected type '%s' instead."); cerr << format(message) % type % repotype_probed << endl; + WAR << format("Unknown repository type '%s'." + " Using detected type '%s' instead.") % type % repotype_probed << endl; + repotype = repotype_probed; } } @@ -395,13 +416,16 @@ void rename_repo(const std::string & alias, const std::string & newalias) { manager.modifyRepository(alias, repo); - cout << format(_("Repository %s renamed to %s")) % alias % repo.alias() << endl; + cout_n << format(_("Repository %s renamed to %s")) % alias % repo.alias() << endl; + MIL << format(_("Repository %s renamed to %s")) % alias % repo.alias() << endl; } catch (const Exception & ex) { cerr << _("Error while modifying the repository:") << endl; cerr << ex.asUserString(); cerr << format(_("Leaving repository %s unchanged.")) % alias << endl; + + ERR << "Error while modifying the repository:" << ex.asUserString() << endl; } } @@ -480,9 +504,11 @@ void warn_if_zmd() { if (system ("pgrep -lx zmd") == 0) { // list name, exact match - cerr << _("ZENworks Management Daemon is running.\n" + cout_n << _("ZENworks Management Daemon is running.\n" "WARNING: this command will not synchronize changes.\n" "Use rug or yast2 for that.\n"); + USR << ("ZMD is running. Tell the user this will get" + " ZMD and libzypp out of sync.") << endl; } } diff --git a/src/zypper.cc b/src/zypper.cc index ee257dc..a2e7f2e 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -20,6 +20,7 @@ #include +#include #include #include "zypper.h" @@ -56,6 +57,7 @@ DigestCallbacks digest_callbacks; static struct option global_options[] = { {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, + {"silent", no_argument, 0, 'S'}, {"version", no_argument, 0, 'V'}, {"terse", no_argument, 0, 't'}, {"table-style", required_argument, 0, 's'}, @@ -136,6 +138,7 @@ ZypperCommand process_globals(int argc, char **argv) string help_global_options = _(" Options:\n" "\t--help, -h\t\tHelp\n" "\t--version, -V\t\tOutput the version number\n" + "\t--silent, -S\t\tSuppress normal output\n" "\t--verbose, -v\t\tIncrease verbosity\n" "\t--terse, -t\t\tTerse output for machine consumption\n" "\t--table-style, -s\tTable style (integer)\n" @@ -143,15 +146,21 @@ ZypperCommand process_globals(int argc, char **argv) "\t--non-interactive\tDon't ask anything, use default answers automatically. (under development)\n" "\t--root, -R \tOperate on a different root directory\n"); ; + + if (gopts.count("silent")) { + gSettings.verbose = -1; + DBG << "Verbosity " << gSettings.verbose << endl; + } if (gopts.count("verbose")) { gSettings.verbose += gopts["verbose"].size(); - cerr << _("Verbosity ") << gSettings.verbose << endl; + cout << _("Verbosity ") << gSettings.verbose << endl; + DBG << _("Verbosity ") << gSettings.verbose << endl; } if (gopts.count("non-interactive")) { gSettings.non_interactive = true; - cout << "Entering non-interactive mode.\n" + cout_n << "Entering non-interactive mode.\n" "WARNING: global non-interactive mode is still under development, use " "with caution. This mode has been implemented and tested for install, " "remove, and update commands so far. In case of problems related to " @@ -175,10 +184,10 @@ ZypperCommand process_globals(int argc, char **argv) // testing option if (gopts.count("opt")) { - cerr << "Opt arg: "; + cout << "Opt arg: "; std::copy (gopts["opt"].begin(), gopts["opt"].end(), - ostream_iterator (cerr, ", ")); - cerr << endl; + ostream_iterator (cout, ", ")); + cout << endl; } // get command @@ -201,16 +210,16 @@ ZypperCommand process_globals(int argc, char **argv) // exception from command parsing catch (Exception & e) { - cerr << e.msg() << endl; + cerr << e.msg() << endl; command = ZypperCommand::NONE; } if (command == ZypperCommand::NONE) { if (ghelp) - cerr << help_global_options << endl << help_commands; + cout << help_global_options << endl << help_commands; else if (gopts.count("version")) - cerr << PACKAGE << endl; + cout << PACKAGE << endl; else cerr << _("Try -h for help") << endl; } @@ -515,19 +524,20 @@ int one_command(const ZypperCommand & command, int argc, char **argv) vector arguments; if (optind < argc) { - cerr_v << _("Non-option program arguments: "); + cout_v << _("Non-option program arguments: "); while (optind < argc) { string argument = argv[optind++]; - cerr_v << argument << ' '; + cout_v << argument << ' '; arguments.push_back (argument); } - cerr_v << endl; + cout_v << endl; } // === process options === if (gopts.count("terse")) { - cerr_v << _("Ignoring --terse (provided only for rug compatibility)") << endl; + cout_v << _("Ignoring --terse (provided only for rug compatibility)") << endl; + WAR << "Ignoring --terse (provided only for rug compatibility)" << endl; } if (gopts.count("disable-system-sources")) @@ -543,7 +553,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) if (gopts.count("disable-system-resolvables")) { MIL << "System resolvables disabled" << endl; - cerr << _("Ignoring installed resolvables...") << endl; + cout_v << _("Ignoring installed resolvables...") << endl; gSettings.disable_system_resolvables = true; } @@ -583,7 +593,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) { if (ghelp) { cout << specific_help << endl; return !ghelp; } - cout << " \\\\\\\\\\\n \\\\\\\\\\\\\\__o\n__\\\\\\\\\\\\\\'/_" << endl; + cout_n << " \\\\\\\\\\\n \\\\\\\\\\\\\\__o\n__\\\\\\\\\\\\\\'/_" << endl; return ZYPPER_EXIT_OK; } @@ -628,12 +638,20 @@ int one_command(const ZypperCommand & command, int argc, char **argv) string type = copts.count("type") ? copts["type"].front() : ""; // display help message if insufficient info was given - if (ghelp || arguments.size() < 1) + if (ghelp || arguments.size() < 2) { - //! todo display_help() - cerr << specific_help; - if (ghelp) return ZYPPER_EXIT_OK; - return ZYPPER_EXIT_ERR_INVALID_ARGS; + if (ghelp) + { + cout << specific_help; + return ZYPPER_EXIT_OK; + } + else + { + cerr << _("Too few arguments. At least URL and alias are required.") << endl; + ERR << "Too few arguments. At least URL and alias are required." << endl; + cout_n << specific_help; + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } } Url url = make_url (arguments[0]); @@ -662,9 +680,20 @@ int one_command(const ZypperCommand & command, int argc, char **argv) else if (command == ZypperCommand::REMOVE_REPO) { - if (ghelp || arguments.size() < 1) { - cerr << specific_help; - return !ghelp; + if (ghelp || arguments.size() < 1) + { + if (ghelp) + { + cout << specific_help; + return ZYPPER_EXIT_OK; + } + else + { + cerr << _("Required argument missing.") << endl; + ERR << "Required argument missing." << endl; + cout_n << specific_help; + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } } warn_if_zmd (); @@ -686,7 +715,21 @@ int one_command(const ZypperCommand & command, int argc, char **argv) else if (command == ZypperCommand::RENAME_REPO) { - if (ghelp || arguments.size() < 2) { cerr << specific_help; return !ghelp; } + if (ghelp || arguments.size() < 2) + { + if (ghelp) + { + cout << specific_help; + return ZYPPER_EXIT_OK; + } + else + { + cerr << _("Too few arguments. At least URL and alias are required.") << endl; + ERR << "Too few arguments. At least URL and alias are required." << endl; + cout_n << specific_help; + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } + } // cond_init_target (); warn_if_zmd (); @@ -783,7 +826,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) ZyppSearchOptions options; if (ghelp) { - cerr << specific_help; + cout << specific_help; return !ghelp; } @@ -820,7 +863,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) search.doSearch(FillTable(t, search.installedCache())); if (t.empty()) - cout << "No packages found." << endl; + cout_n << "No packages found." << endl; else { if (copts.count("sort-by-catalog")) t.sort(1); else t.sort(3); // sort by name @@ -835,7 +878,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) // TODO: rug summary else if (command == ZypperCommand::PATCH_CHECK) { if (ghelp) { - cerr << specific_help; + cout << specific_help; return !ghelp; } @@ -862,7 +905,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) else if (command == ZypperCommand::SHOW_PATCHES) { if (ghelp) { - cerr << specific_help; + cout << specific_help; return !ghelp; } @@ -879,7 +922,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) else if (command == ZypperCommand::LIST_UPDATES) { if (ghelp) { // FIXME catalog... - cerr << specific_help; + cout << specific_help; return !ghelp; } @@ -904,7 +947,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) // -----------------------------( update )---------------------------------- else if (command == ZypperCommand::UPDATE) { - if (ghelp) { cerr << specific_help; return !ghelp; } + if (ghelp) { cout << specific_help; return !ghelp; } string skind = copts.count("type")? copts["type"].front() : gSettings.is_rug_compatible? "package" : "patch"; diff --git a/src/zypper.h b/src/zypper.h index 5a7bc03..afdf43a 100644 --- a/src/zypper.h +++ b/src/zypper.h @@ -36,6 +36,9 @@ #define ZYPPER_EXIT_INF_REBOOT_NEEDED 102 // reboot needed after install/upgrade #define ZYPPER_EXIT_INF_RESTART_NEEDED 103 // restart of package manager itself needed +/** + * Structure for holding various start-up setting. + */ struct Settings { Settings() @@ -51,6 +54,17 @@ struct Settings std::list additional_sources; std::string previous_token; + + /** + * Level of the amount of output. + * + *
    + *
  • -1 silent
  • + *
  • 0 normal (default)
  • + *
  • 1 verbose
  • + *
  • 2 debug
  • + *
+ */ int verbose; int previous_code; std::string command; @@ -88,11 +102,33 @@ extern RuntimeData gData; extern Settings gSettings; extern std::ostream no_stream; -#define COND_STREAM(STREAM,LEVEL) ((gSettings.verbose >= LEVEL)? STREAM: no_stream) -#define cerr_v COND_STREAM(cerr,1) -#define cout_v COND_STREAM(cout,1) -#define cerr_vv COND_STREAM(cerr,2) -#define cout_vv COND_STREAM(cout,2) +/** + * Macro to filter output above the current verbosity level. + * + * \see Output Macros + * \see Settings::verbose + */ +#define COND_STREAM(STREAM,LEVEL) ((gSettings.verbose >= LEVEL) ? STREAM : no_stream) + +/** \name Output Macros + * Alway use these macros to produce output so that the verbosity options + * like -v or --silent are respected. Use standard cout and cerr only in + * cases where it is desirable to ignore them (e.g. help texts (when -h is + * used) or brief error messages must always be displayed, even if --silent + * has been specified). + */ +//!@{ +//! normal output +#define cout_n COND_STREAM(cout, 0) +//! verbose output +#define cout_v COND_STREAM(cout, 1) +//! verbose error output +#define cerr_v COND_STREAM(cerr, 1) +//! debug info output +#define cout_vv COND_STREAM(cout, 2) +//! debug error output (details) +#define cerr_vv COND_STREAM(cerr, 2) +//!@} // undefine _ macro from libzypp #ifdef _