1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/**************************************************************************
* Copyright (C) 2010-2011 by Eugene V. Lyubimkin *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License *
* (version 3 or above) as published by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU GPL *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
**************************************************************************/
#include <clocale>
#include <iostream>
using std::cout;
using std::endl;
#include <map>
#include "cupt.hpp"
#include "misc.hpp"
#include "version.hpp"
void showOwnVersion();
void showHelp(const char*);
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "");
cupt::messageFd = STDERR_FILENO;
Context context;
return mainEx(argc, argv, context);
}
namespace {
bool showHelpOrOwnVersion(int argc, char* argv[])
{
if (argc > 1)
{
if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version") || !strcmp(argv[1], "-v"))
{
if (argc > 2)
{
warn2(__("the command '%s' doesn't accept arguments"), argv[1]);
}
showOwnVersion();
return true;
}
if (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))
{
if (argc > 2)
{
warn2(__("the command '%s' doesn't accept arguments"), argv[1]);
}
showHelp(argv[0]);
return true;
}
}
else
{
showHelp(argv[0]);
return true;
}
return false;
}
}
int mainEx(int argc, char* argv[], Context& context)
{
try
{
if (showHelpOrOwnVersion(argc, argv))
return 0;
auto command = parseCommonOptions(argc, argv, /* in */ *context.getConfig(),
/* out */ context.unparsed);
context.argc = argc;
context.argv = argv;
std::function< int (Context&) > handler = getHandler(command);
try
{
return handler(context);
}
catch (Exception&)
{
fatal2(__("error performing the command '%s'"), command);
}
}
catch (Exception&)
{
return 1;
}
return 255; // we should not reach it, and gcc issues internal error on __builtin_unreachable
}
void showOwnVersion()
{
cout << "executable: " << CUPT_VERSION << endl;
cout << "library: " << cupt::libraryVersion << endl;
}
void showHelp(const char* argv0)
{
using std::map;
map< string, string > actionDescriptions = {
{ "help", __("prints a short help") },
{ "version", __("prints versions of this program and the underlying library") },
{ "config-dump", __("prints values of configuration variables") },
{ "show", __("prints the info about binary package(s)") },
{ "showsrc", __("prints the info about source packages(s)") },
{ "search", __("searches for packages using regular expression(s)") },
{ "depends", __("prints dependencies of binary package(s)") },
{ "rdepends", __("print reverse-dependencies of binary package(s)") },
{ "why", __("finds a dependency path between a package set and a package") },
{ "policy", __("prints the pin info for the binary package(s)") },
{ "policysrc", __("prints the pin info for the source package(s)") },
{ "pkgnames", __("prints available package names") },
{ "changelog", __("views the Debian changelog(s) of binary package(s)") },
{ "copyright", __("views the Debian copyright(s) info of binary package(s)") },
{ "screenshots", __("views Debian screenshot web pages for binary package(s)") },
{ "update", __("updates repository metadata") },
{ "install", __("installs/upgrades/downgrades binary package(s)") },
{ "reinstall", __("reinstalls binary packages(s)") },
{ "remove", __("removes binary package(s)") },
{ "purge", __("removes binary package(s) along with their configuration files") },
{ "iii", __("\"install if installed\": upgrades/downgrades binary packages(s)") },
{ "satisfy", __("performs actions to make relation expressions satisfied") },
{ "safe-upgrade", __("upgrades the system without removing non-automatically installed packages") },
{ "full-upgrade", __("upgrades the system") },
{ "dist-upgrade", __("does a two-stage full upgrade") },
{ "build-dep", __("satisfies build dependencies for source package(s)") },
{ "source", __("fetches and unpacks source package(s)") },
{ "clean", __("cleans the whole binary package cache") },
{ "autoclean", __("cleans packages from the binary package cache if not available from repositories") },
{ "markauto", __("marks binary package(s) as automatically installed") },
{ "unmarkauto", __("marks binary package(s) as manually installed") },
{ "showauto", __("shows the list of manually or automatically installed packages") },
{ "shell", __("starts an interactive package manager shell") },
{ "snapshot", __("works with system snapshots") },
};
cout << format2(__("Usage: %s <action> [<parameters>]"), argv0) << endl;
cout << endl;
cout << __("Actions:") << endl;
for (const auto& pair: actionDescriptions)
{
cout << " " << pair.first << ": " << pair.second << endl;
}
}
|