Author: jkupec Date: Sun Dec 9 16:57:30 2007 New Revision: 8082 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8082&view=rev Log: - removed the exit machinery, EditRequestException retained - quit command help added Modified: trunk/zypper/src/zypper.cc trunk/zypper/src/zypper.h Modified: trunk/zypper/src/zypper.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=8082&r1=8081&r2=8082&view=diff ============================================================================== --- trunk/zypper/src/zypper.cc (original) +++ trunk/zypper/src/zypper.cc Sun Dec 9 16:57:30 2007 @@ -54,7 +54,7 @@ Zypper::Zypper() : _argc(0), _argv(NULL), _command(ZypperCommand::NONE), - _exiting(false), _exit_code(ZYPPER_EXIT_OK), + _exit_code(ZYPPER_EXIT_OK), _running_shell(false), _running_help(false), _sh_argc(0), _sh_argv(NULL) { @@ -84,9 +84,12 @@ _argv = argv; // parse global options and the command - processGlobalOptions(); - if (this->exiting()) + try { processGlobalOptions(); } + catch (const ExitRequestException & e) + { + MIL << "Caught exit request:" << endl << e.msg() << endl; return exitCode(); + } switch(command().toEnum()) { @@ -360,14 +363,14 @@ { cout << e.asUserString() << endl; print_unknown_command_hint(); - this->exit(); + ZYPP_THROW(ExitRequestException("help provided")); } } } else { print_main_help(); - this->exit(); + ZYPP_THROW(ExitRequestException("help provided")); } } else if (command() == ZypperCommand::NONE) @@ -482,8 +485,6 @@ _command_help.clear(); // reset help flag setRunningHelp(false); - // reset the exitting flag - exit(false); // ... and the exit code setExitCode(ZYPPER_EXIT_OK); @@ -505,7 +506,7 @@ try { processCommandOptions(); - if (exiting() || command() == ZypperCommand::NONE) + if (command() == ZypperCommand::NONE) return; doCommand(); } @@ -518,7 +519,7 @@ } catch (const ExitRequestException & e) { - cout_vv << "Caught exit request:" << endl << e.msg() << endl; + MIL << "Caught exit request:" << endl << e.msg() << endl; } catch (const Exception & ex) { @@ -1099,6 +1100,23 @@ break; } + case ZypperCommand::SHELL_QUIT_e: + { + static struct option quit_options[] = { + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + specific_options = quit_options; + _command_help = _( + "quit (exit, ^D)\n" + "\n" + "Quit the current zypper shell.\n" + "\n" + "This command has no additional options.\n" + ); + break; + } + default: { ERR << "Unknown or unexpected command" << endl; @@ -2013,6 +2031,18 @@ return; } + else if (command() == ZypperCommand::SHELL_QUIT) + { + if (runningHelp()) + cout << _command_help; + else if (!runningShell()) + cout << _("This command only makes sense in the zypper shell.") << endl; + else + cout << "oops, you wanted to quit, didn't you?" << endl; + + return; + } + // if the program reaches this line, something went wrong setExitCode(ZYPPER_EXIT_ERR_BUG); } Modified: trunk/zypper/src/zypper.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.h?rev=8082&r1=8081&r2=8082&view=diff ============================================================================== --- trunk/zypper/src/zypper.h (original) +++ trunk/zypper/src/zypper.h Sun Dec 9 16:57:30 2007 @@ -4,6 +4,7 @@ #include <string> #include <vector> +#include "zypp/base/Exception.h" #include "zypp/base/ReferenceCounted.h" #include "zypp/base/NonCopyable.h" #include "zypp/base/PtrTypes.h" @@ -83,10 +84,6 @@ const ZypperCommand & command() const { return _command; } const std::string & commandHelp() const { return _command_help; } const std::vectorstd::string & arguments() const { return _arguments; } - /** Check whether is exiting (has entered the exit path). \see _exiting */ - int exiting() const { return _exiting; } - /** Tell zypper to enter the exit path \see _exiting */ - void exit(bool value = true) { _exiting = value; } int exitCode() const { return _exit_code; } void setExitCode(int exit) { _exit_code = exit; } bool runningShell() const { return _running_shell; } @@ -124,10 +121,6 @@ std::vectorstd::string _arguments; std::string _command_help; - /** Indicates that zypper is exiting through exit checkers like - * <tt>if (zypper.exiting()) return;</tt>. To be used for SIGINT or SIGTERM - * handling */ - bool _exiting; int _exit_code; bool _running_shell; bool _running_help; @@ -158,15 +151,15 @@ extern RuntimeData gData; extern std::ostream no_stream; -class ExitRequestException +class ExitRequestException : public zypp::Exception { public: - ExitRequestException(const std::string & msg = "") : _msg(msg) {} - ~ExitRequestException() {} + ExitRequestException(const std::string & msg = "") : zypp::Exception(msg) {} +// ExitRequestException(const std::string & msg = "") : _msg(msg) {} - const std::string & msg() const { return _msg; } +// const std::string & msg() const { return _msg; } private: - std::string _msg; +// std::string _msg; }; #endif /*ZYPPER_H*/ -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org