Author: jkupec Date: Mon Sep 10 15:29:34 2007 New Revision: 7164 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7164&view=rev Log: - report too many arguments (#307639) Modified: trunk/zypper/src/zypper-callbacks.cc trunk/zypper/src/zypper-callbacks.h trunk/zypper/src/zypper.cc Modified: trunk/zypper/src/zypper-callbacks.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-callbacks.cc?rev=7164&r1=7163&r2=7164&view=diff ============================================================================== --- trunk/zypper/src/zypper-callbacks.cc (original) +++ trunk/zypper/src/zypper-callbacks.cc Mon Sep 10 15:29:34 2007 @@ -197,6 +197,8 @@ cerr << endl; } +// ---------------------------------------------------------------------------- + void report_problem(const zypp::Exception & e, const string & problem_desc, const string & hint) @@ -212,6 +214,16 @@ cerr << hint << endl; } +// ---------------------------------------------------------------------------- + +void report_too_many_arguments(const string & specific_help) +{ + //! \todo make this more explanatory, e.g. "Ingoring arg1 arg2. This command does not take arguments. See %s for more information." + cerr << _("Too many arguments") << '.' << endl; + cout_n << _("Usage") << ':' << endl; + cout_n << specific_help; +} + // Local Variables: // c-basic-offset: 2 // End: Modified: trunk/zypper/src/zypper-callbacks.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-callbacks.h?rev=7164&r1=7163&r2=7164&view=diff ============================================================================== --- trunk/zypper/src/zypper-callbacks.h (original) +++ trunk/zypper/src/zypper-callbacks.h Mon Sep 10 15:29:34 2007 @@ -97,4 +97,9 @@ const string & problem_desc, const string & hint = ""); +/** + * + */ +void report_too_many_arguments(const string & specific_help); + #endif Modified: trunk/zypper/src/zypper.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=7164&r1=7163&r2=7164&view=diff ============================================================================== --- trunk/zypper/src/zypper.cc (original) +++ trunk/zypper/src/zypper.cc Mon Sep 10 15:29:34 2007 @@ -796,6 +796,13 @@ return ZYPPER_EXIT_ERR_PRIVILEGES; } + // too many arguments + if (arguments.size() > 2) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } + // indeterminate indicates the user has not specified the values tribool enabled(indeterminate); tribool refresh(indeterminate); @@ -878,10 +885,19 @@ { cerr << _("Required argument missing.") << endl; ERR << "Required argument missing." << endl; + cout_n << _("Usage") << ':' << endl; cout_n << specific_help; return ZYPPER_EXIT_ERR_INVALID_ARGS; } + // too many arguments + //! \todo allow to specify multiple repos to delete + else if (arguments.size() > 1) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } + warn_if_zmd (); bool found = remove_repo(arguments[0]); @@ -952,6 +968,12 @@ cout_n << specific_help; return ZYPPER_EXIT_ERR_INVALID_ARGS; } + // too many arguments + else if (arguments.size() > 2) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } // cond_init_target (); warn_if_zmd (); @@ -992,6 +1014,12 @@ cout_n << specific_help; return ZYPPER_EXIT_ERR_INVALID_ARGS; } + // too many arguments + if (arguments.size() > 1) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } modify_repo(arguments[0]); } @@ -1145,9 +1173,10 @@ { ZyppSearchOptions options; - if (ghelp) { + if (ghelp) + { cout << specific_help; - return !ghelp; + return ZYPPER_EXIT_OK; } if (gSettings.disable_system_resolvables || copts.count("uninstalled-only")) @@ -1220,9 +1249,17 @@ // TODO: rug summary else if (command == ZypperCommand::PATCH_CHECK) { - if (ghelp) { + if (ghelp) + { cout << specific_help; - return !ghelp; + return ZYPPER_EXIT_OK; + } + + // too many arguments + if (arguments.size() > 0) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; } cond_init_target (); @@ -1251,9 +1288,17 @@ // --------------------------( patches )------------------------------------ else if (command == ZypperCommand::SHOW_PATCHES) { - if (ghelp) { + if (ghelp) + { cout << specific_help; - return !ghelp; + return ZYPPER_EXIT_OK; + } + + // too many arguments + if (arguments.size() > 0) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; } cond_init_target (); @@ -1269,10 +1314,17 @@ // --------------------------( list updates )------------------------------- else if (command == ZypperCommand::LIST_UPDATES) { - if (ghelp) { - // FIXME catalog... + if (ghelp) + { cout << specific_help; - return !ghelp; + return ZYPPER_EXIT_OK; + } + + // too many arguments + if (arguments.size() > 0) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; } string skind = copts.count("type")? copts["type"].front() : @@ -1307,8 +1359,11 @@ // -----------------( xml list updates and patches )------------------------ else if (command == ZypperCommand::XML_LIST_UPDATES_PATCHES) { - - if (ghelp) { cout << specific_help << endl; return !ghelp; } + if (ghelp) + { + cout << specific_help; + return ZYPPER_EXIT_OK; + } cond_init_target (); int initret = init_repos(); @@ -1330,7 +1385,11 @@ // -----------------------------( update )---------------------------------- else if (command == ZypperCommand::UPDATE) { - if (ghelp) { cout << specific_help; return !ghelp; } + if (ghelp) + { + cout << specific_help; + return ZYPPER_EXIT_OK; + } // check root user if (geteuid() != 0) @@ -1339,6 +1398,13 @@ return ZYPPER_EXIT_ERR_PRIVILEGES; } + // too many arguments + if (arguments.size() > 0) + { + report_too_many_arguments(specific_help); + return ZYPPER_EXIT_ERR_INVALID_ARGS; + } + // rug compatibility code // switch on non-interactive mode if no-confirm specified if (copts.count("no-confirm")) @@ -1396,9 +1462,19 @@ else if (command == ZypperCommand::INFO || command == ZypperCommand::RUG_PATCH_INFO) { - if (ghelp || arguments.size() == 0) { - cerr << specific_help; - return !ghelp; + if (ghelp) + { + cout << specific_help; + return ZYPPER_EXIT_OK; + } + + if (arguments.size() < 1) + { + cerr << _("Required argument missing.") << endl; + ERR << "Required argument missing." << endl; + cout_n << _("Usage") << ':' << endl; + cout_n << specific_help; + return ZYPPER_EXIT_ERR_INVALID_ARGS; } cond_init_target (); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org