[zypp-commit] r10963 - in /trunk/zypper/src: Command.cc Command.h Zypper.cc
Author: jkupec Date: Mon Sep 8 20:33:58 2008 New Revision: 10963 URL: http://svn.opensuse.org/viewcvs/zypp?rev=10963&view=rev Log: - targetos command added - versioncmp command added Modified: trunk/zypper/src/Command.cc trunk/zypper/src/Command.h trunk/zypper/src/Zypper.cc Modified: trunk/zypper/src/Command.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/Command.cc?rev=10963&r1=10962&r2=10963&view=diff ============================================================================== --- trunk/zypper/src/Command.cc (original) +++ trunk/zypper/src/Command.cc Mon Sep 8 20:33:58 2008 @@ -60,6 +60,9 @@ const ZypperCommand ZypperCommand::LIST_LOCKS(ZypperCommand::LIST_LOCKS_e); const ZypperCommand ZypperCommand::CLEAN_LOCKS(ZypperCommand::CLEAN_LOCKS_e); +const ZypperCommand ZypperCommand::TARGET_OS(ZypperCommand::TARGET_OS_e); +const ZypperCommand ZypperCommand::VERSION_CMP(ZypperCommand::VERSION_CMP_e); + const ZypperCommand ZypperCommand::HELP(ZypperCommand::HELP_e); const ZypperCommand ZypperCommand::SHELL(ZypperCommand::SHELL_e); const ZypperCommand ZypperCommand::SHELL_QUIT(ZypperCommand::SHELL_QUIT_e); @@ -127,6 +130,9 @@ _table["locks"] = _table["ll"] = _table["lock-list"] = ZypperCommand::LIST_LOCKS_e; _table["cleanlocks"] = _table["cl"] = _table["lock-clean"] = ZypperCommand::CLEAN_LOCKS_e; + _table["targetos"] = _table["tos"] = ZypperCommand::TARGET_OS_e; + _table["versioncmp"] = _table["vcmp"] = ZypperCommand::VERSION_CMP_e; + _table["help"] = _table["?"] = ZypperCommand::HELP_e; _table["shell"] = _table["sh"] = ZypperCommand::SHELL_e; _table["quit"] = _table["exit"] = _table["\004"] = ZypperCommand::SHELL_QUIT_e; Modified: trunk/zypper/src/Command.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/Command.h?rev=10963&r1=10962&r2=10963&view=diff ============================================================================== --- trunk/zypper/src/Command.h (original) +++ trunk/zypper/src/Command.h Mon Sep 8 20:33:58 2008 @@ -54,6 +54,10 @@ static const ZypperCommand REMOVE_LOCK; static const ZypperCommand LIST_LOCKS; static const ZypperCommand CLEAN_LOCKS; + + // utils/others + static const ZypperCommand TARGET_OS; + static const ZypperCommand VERSION_CMP; static const ZypperCommand HELP; static const ZypperCommand SHELL; @@ -118,6 +122,9 @@ LIST_LOCKS_e, CLEAN_LOCKS_e, + TARGET_OS_e, + VERSION_CMP_e, + HELP_e, SHELL_e, SHELL_QUIT_e, Modified: trunk/zypper/src/Zypper.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/Zypper.cc?rev=10963&r1=10962&r2=10963&view=diff ============================================================================== --- trunk/zypper/src/Zypper.cc (original) +++ trunk/zypper/src/Zypper.cc Mon Sep 8 20:33:58 2008 @@ -390,7 +390,7 @@ { _gopts.machine_readable = true; _gopts.no_abbrev = true; - out().error("--terse is not implemented, does nothing"); + //out().error("--terse is not implemented, does nothing"); } // ======== other global options ======== @@ -1841,6 +1841,42 @@ break; } + case ZypperCommand::TARGET_OS_e: + { + static struct option options[] = + { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + specific_options = options; + _command_help = _( + "targetos (tos)\n" + "\n" + "Show the ID string of the target Operating System.\n" + "\n" + "This command has no additional options.\n" + ); + break; + } + + case ZypperCommand::VERSION_CMP_e: + { + static struct option options[] = + { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + specific_options = options; + _command_help = _( + "versioncmp (vcmp) <version1> <version2>\n" + "\n" + "Compare the versions supplied as arguments.\n" + "\n" + "This command has no additional options.\n" + ); + break; + } + case ZypperCommand::SHELL_QUIT_e: { static struct option quit_options[] = { @@ -3426,6 +3462,76 @@ break; } + + // ----------------------------(utils/others)-------------------------------- + + case ZypperCommand::TARGET_OS_e: + { + if (runningHelp()) { out().info(_command_help, Out::QUIET); return; } + + // needed to be able to retrieve the target distribution + init_target(*this); + + out().info(God->target()->targetDistribution()); + + break; + } + + case ZypperCommand::VERSION_CMP_e: + { + if (runningHelp()) { out().info(_command_help, Out::QUIET); return; } + + if (_arguments.size() < 2) + { + report_required_arg_missing(out(), _command_help); + setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + return; + } + else if (_arguments.size() > 2) + { + report_too_many_arguments(_command_help); + setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + return; + } + + Edition lhs(_arguments[0]); + Edition rhs(_arguments[1]); + + if (lhs.empty()) + { + out().info(str::form( + _("'%s' is not a valid version number."), _arguments[0].c_str())); + setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + return; + } + + if (rhs.empty()) + { + out().info(str::form( + _("'%s' is not a valid version number."), _arguments[1].c_str())); + setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + return; + } + + int result = lhs.match(rhs); + + // be terse when talking to machines + if (_gopts.machine_readable) + { + out().info(str::numstring(result)); + break; + } + + // tell a human + if (result == 0) + out().info(str::form(_("%s matches %s"), lhs.asString().c_str(), rhs.asString().c_str())); + else if (result > 0) + out().info(str::form(_("%s is newer than %s"), lhs.asString().c_str(), rhs.asString().c_str())); + else + out().info(str::form(_("%s is older than %s"), lhs.asString().c_str(), rhs.asString().c_str())); + + break; + } // -----------------------------( shell )------------------------------------ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
jkupec@svn.opensuse.org