]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode: cpp; mode: fold -*- | |
2 | // Description /*{{{*/ | |
3 | /* ###################################################################### | |
4 | ||
5 | apt - CLI UI for apt | |
6 | ||
7 | Returns 100 on failure, 0 on success. | |
8 | ||
9 | ##################################################################### */ | |
10 | /*}}}*/ | |
11 | // Include Files /*{{{*/ | |
12 | #include<config.h> | |
13 | ||
14 | #include <apt-pkg/cmndline.h> | |
15 | #include <apt-pkg/error.h> | |
16 | #include <apt-pkg/init.h> | |
17 | #include <apt-pkg/pkgsystem.h> | |
18 | #include <apt-pkg/strutl.h> | |
19 | #include <apt-pkg/configuration.h> | |
20 | ||
21 | #include <apt-private/private-list.h> | |
22 | #include <apt-private/private-search.h> | |
23 | #include <apt-private/private-install.h> | |
24 | #include <apt-private/private-output.h> | |
25 | #include <apt-private/private-update.h> | |
26 | #include <apt-private/private-cmndline.h> | |
27 | #include <apt-private/private-moo.h> | |
28 | #include <apt-private/private-upgrade.h> | |
29 | #include <apt-private/private-show.h> | |
30 | #include <apt-private/private-main.h> | |
31 | #include <apt-private/private-sources.h> | |
32 | ||
33 | #include <unistd.h> | |
34 | #include <iostream> | |
35 | #include <vector> | |
36 | ||
37 | #include <apti18n.h> | |
38 | /*}}}*/ | |
39 | ||
40 | bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/ | |
41 | { | |
42 | ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); | |
43 | ||
44 | // FIXME: generate from CommandLine | |
45 | std::cout << | |
46 | _("Usage: apt [options] command\n" | |
47 | "\n" | |
48 | "CLI for apt.\n") | |
49 | << std::endl | |
50 | << _("Commands:") << std::endl; | |
51 | for (; Cmds->Handler != nullptr; ++Cmds) | |
52 | { | |
53 | if (Cmds->Help == nullptr) | |
54 | continue; | |
55 | std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl; | |
56 | } | |
57 | ||
58 | return true; | |
59 | } | |
60 | /*}}}*/ | |
61 | std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/ | |
62 | { | |
63 | return { | |
64 | // query | |
65 | {"list", &DoList, _("list packages based on package names")}, | |
66 | {"search", &DoSearch, _("search in package descriptions")}, | |
67 | {"show", &ShowPackage, _("show package details")}, | |
68 | ||
69 | // package stuff | |
70 | {"install", &DoInstall, _("install packages")}, | |
71 | {"remove", &DoInstall, _("remove packages")}, | |
72 | {"autoremove", &DoInstall, _("Remove automatically all unused packages")}, | |
73 | {"auto-remove", &DoInstall, nullptr}, | |
74 | {"purge", &DoInstall, nullptr}, | |
75 | ||
76 | // system wide stuff | |
77 | {"update", &DoUpdate, _("update list of available packages")}, | |
78 | {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")}, | |
79 | {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")}, | |
80 | {"dist-upgrade", &DoDistUpgrade, nullptr}, // for compat with muscle memory | |
81 | ||
82 | // misc | |
83 | {"edit-sources", &EditSources, _("edit the source information file")}, | |
84 | {"moo", &DoMoo, nullptr}, | |
85 | {nullptr, nullptr, nullptr} | |
86 | }; | |
87 | } | |
88 | /*}}}*/ | |
89 | int main(int argc, const char *argv[]) /*{{{*/ | |
90 | { | |
91 | InitLocale(); | |
92 | ||
93 | CommandLine CmdL; | |
94 | auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv); | |
95 | ||
96 | int const quiet = _config->FindI("quiet", 0); | |
97 | if (quiet == 2) | |
98 | { | |
99 | _config->CndSet("quiet::NoProgress", true); | |
100 | _config->Set("quiet", 1); | |
101 | } | |
102 | ||
103 | InitSignals(); | |
104 | InitOutput(); | |
105 | ||
106 | CheckIfCalledByScript(argc, argv); | |
107 | CheckIfSimulateMode(CmdL); | |
108 | ||
109 | return DispatchCommandLine(CmdL, Cmds); | |
110 | } | |
111 | /*}}}*/ |