#include "zypper-search.h"
#include "zypper-info.h"
#include "zypper-getopt.h"
+#include "zypper-command.h"
using namespace std;
//using namespace boost;
}
/// process one command from the OS shell or the zypper shell
-int one_command(const string& command, int argc, char **argv)
+int one_command(const string& command_str, int argc, char **argv)
{
// === command-specific options ===
+ ZypperCommand command(command_str);
+
struct option no_options = {0, 0, 0, 0};
struct option *specific_options = &no_options;
string specific_help;
"\t--disable-system-resolvables, -T\t\tDo not read system installed resolvables\n"
);
- if (command == "install" || command == "in") {
+ if (command.toEnum() == ZypperCommand::INSTALL_e) {
static struct option install_options[] = {
{"catalog", required_argument, 0, 'c'},
{"type", required_argument, 0, 't'},
"\t--no-confirm,-y\tDo not require user confirmation\n"
);
}
- else if (command == "remove" || command == "rm") {
+ else if (command.toEnum() == ZypperCommand::REMOVE_e) {
static struct option remove_options[] = {
{"type", required_argument, 0, 't'},
{"no-confirm", no_argument, 0, 'y'},
"\t--no-confirm,-y\tDo not require user confirmation\n"
);
}
- else if (command == "service-add" || command == "sa") {
+ else if (command.toEnum() == ZypperCommand::ADD_REPO_e) {
static struct option service_add_options[] = {
{"type", required_argument, 0, 't'},
{"disabled", no_argument, 0, 'd'},
"\t--no-refresh,-n\t\tDo not automatically refresh the metadata\n"
);
}
- else if (command == "service-list" || command == "sl") {
+ else if (command.toEnum() == ZypperCommand::LIST_REPOS_e) {
static struct option service_list_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command == "service-delete" || command == "sd") {
+ else if (command.toEnum() == ZypperCommand::REMOVE_REPO_e) {
static struct option service_delete_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command == "service-rename" || command == "sr") {
+ else if (command_str == "service-rename" || command_str == "sr") {
static struct option service_rename_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command == "refresh" || command == "ref") {
+ else if (command.toEnum() == ZypperCommand::REFRESH_e) {
static struct option refresh_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"Refresh all installation sources found in the system.\n"
);
}
- else if (command == "list-updates" || command == "lu") {
+ else if (command_str == "list-updates" || command_str == "lu") {
static struct option list_updates_options[] = {
{"type", required_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
"\t--type,-t\t\tType of resolvable (default: patch)\n"
);
}
- else if (command == "update" || command == "up") {
+ else if (command_str == "update" || command_str == "up") {
static struct option update_options[] = {
{"type", required_argument, 0, 't'},
{"no-confirm", no_argument, 0, 'y'},
"\t--skip-interactive\t\tSkip interactive updates\n"
);
}
- else if (command == "search" || command == "se") {
+ else if (command_str == "search" || command_str == "se") {
static struct option search_options[] = {
{"installed-only", no_argument, 0, 'i'},
{"uninstalled-only", no_argument, 0, 'u'},
"* and ? wildcards can also be used within search strings.\n"
);
}
- else if (command == "patch-check" || command == "pchk") {
+ else if (command_str == "patch-check" || command_str == "pchk") {
static struct option patch_check_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command == "patches" || command == "pch") {
+ else if (command_str == "patches" || command_str == "pch") {
static struct option patches_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"This command has no options.\n"
);
}
- else if (command == "info" || command == "if") {
+ else if (command_str == "info" || command_str == "if") {
static struct option info_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"'info' -- Show full information for packages\n"
);
}
- else if (command == "patch-info") {
+ else if (command_str == "patch-info") {
static struct option patch_info_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"'patch-info' -- Show detailed information for patches\n"
);
}
- else if (command == "moo") {
+ else if (command_str == "moo") {
static struct option moo_options[] = {
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
"'moo' - Show an animal\n"
);
}
- else if (!command.empty()) { // empty command is treated earlier
- if (command != "help") // #235709
- cerr << _("Unknown command") << " '" << command << "'." << endl << endl;
+ else if (!command_str.empty()) { // empty command is treated earlier
+ if (command_str != "help") // #235709
+ cerr << _("Unknown command") << " '" << command_str << "'." << endl << endl;
cerr << help_commands;
return ZYPPER_EXIT_ERR_SYNTAX;
}
// here come commands that need the lock
try {
- if (command == "service-list" || command == "sl")
+ if (command_str == "service-list" || command_str == "sl")
zypp_readonly_hack::IWantIt (); // #247001
God = zypp::getZYpp();
// --------------------------( moo )----------------------------------------
- if (command == "moo") {
+ if (command_str == "moo") {
cout << " \\\\\\\\\\\n \\\\\\\\\\\\\\__o\n__\\\\\\\\\\\\\\'/_" << endl;
return ZYPPER_EXIT_OK;
}
// --------------------------( service list )-------------------------------
- else if (command == "service-list" || command == "sl")
+ else if (command.toEnum() == ZypperCommand::LIST_REPOS_e)
{
if (ghelp) {
cerr << specific_help << endl;
// --------------------------( service add )--------------------------------
- else if (command == "service-add" || command == "sa")
+ else if (command.toEnum() == ZypperCommand::ADD_REPO_e)
{
// TODO: repect values in .repo, have these as overrides
bool enabled = ! copts.count("disabled");
// --------------------------( service delete )-----------------------------
- else if (command == "service-delete" || command == "sd")
+ else if (command.toEnum() == ZypperCommand::REMOVE_REPO_e)
{
if (ghelp || arguments.size() < 1) {
cerr << specific_help;
// --------------------------( service rename )-----------------------------
- else if (command == "service-rename" || command == "sr")
+ else if (command_str == "service-rename" || command_str == "sr")
{
if (ghelp || arguments.size() < 2) {
cerr << specific_help;
// --------------------------( refresh )------------------------------------
- else if (command == "refresh" || command == "ref") {
- if (ghelp) {
- cerr << specific_help;
- return !ghelp;
- }
-
+ else if (command.toEnum() == ZypperCommand::REFRESH_e)
+ {
+ if (ghelp) { cout << specific_help; return !ghelp; }
+
refresh_sources();
}
// --------------------------( remove/install )-----------------------------
- else if (command == "install" || command == "in" ||
- command == "remove" || command == "rm") {
-
- if (command == "install" || command == "in") {
+ else if (command.toEnum() == ZypperCommand::INSTALL_e ||
+ command.toEnum() == ZypperCommand::REMOVE_e )
+ {
+ if (command.toEnum() == ZypperCommand::INSTALL_e) {
if (ghelp || arguments.size() < 1) {
cerr << "install [options] name...\n" << specific_help;
return !ghelp;
gData.packages_to_install = arguments;
}
- if (command == "remove" || command == "rm") {
+ if (command.toEnum() == ZypperCommand::REMOVE_e) {
if (ghelp || arguments.size() < 1) {
cerr << "remove [options] name...\n"
<< specific_help
cout_v << "DONE" << endl;
for ( vector<string>::const_iterator it = arguments.begin(); it != arguments.end(); ++it ) {
- if (command == "install" || command == "in") {
+ if (command.toEnum() == ZypperCommand::INSTALL_e) {
mark_for_install(kind, *it);
}
else {
// TODO -c, --catalog option
- else if (command == "search" || command == "se") {
+ else if (command_str == "search" || command_str == "se") {
ZyppSearchOptions options;
if (ghelp) {
// --------------------------( patch check )--------------------------------
// TODO: rug summary
- else if (command == "patch-check" || command == "pchk") {
+ else if (command_str == "patch-check" || command_str == "pchk") {
if (ghelp) {
cerr << specific_help;
return !ghelp;
// --------------------------( patches )------------------------------------
- else if (command == "patches" || command == "pch") {
+ else if (command_str == "patches" || command_str == "pch") {
if (ghelp) {
cerr << specific_help;
return !ghelp;
// --------------------------( list updates )-------------------------------
- else if (command == "list-updates" || command == "lu") {
+ else if (command_str == "list-updates" || command_str == "lu") {
if (ghelp) {
// FIXME catalog...
cerr << specific_help;
// -----------------------------( update )----------------------------------
- else if (command == "update" || command == "up") {
+ else if (command_str == "update" || command_str == "up") {
if (ghelp) {
cerr << "update [options]\n"
<< specific_help
// -----------------------------( info )------------------------------------
- else if (command == "info" || command == "if" || command == "patch-info") {
+ else if (command_str == "info" || command_str == "if" || command_str == "patch-info") {
if (ghelp || arguments.size() == 0) {
cerr << specific_help;
return !ghelp;
cond_load_resolvables ();
establish ();
- printInfo(command,arguments);
+ printInfo(command_str,arguments);
return ZYPPER_EXIT_OK;
}