]>
Commit | Line | Data |
---|---|---|
b9179170 MV |
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 | ||
453b82a3 | 14 | #include <apt-pkg/cmndline.h> |
b9179170 | 15 | #include <apt-pkg/error.h> |
b9179170 | 16 | #include <apt-pkg/init.h> |
b9179170 | 17 | #include <apt-pkg/pkgsystem.h> |
453b82a3 DK |
18 | #include <apt-pkg/strutl.h> |
19 | #include <apt-pkg/configuration.h> | |
b9179170 MV |
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> | |
9e6b13f3 | 31 | #include <apt-private/private-sources.h> |
b9179170 | 32 | |
453b82a3 DK |
33 | #include <unistd.h> |
34 | #include <iostream> | |
35 | #include <vector> | |
cfacba52 | 36 | |
453b82a3 DK |
37 | #include <apti18n.h> |
38 | /*}}}*/ | |
cfacba52 | 39 | |
65512241 | 40 | static bool ShowHelp(CommandLine &) |
b9179170 MV |
41 | { |
42 | ioprintf(c1out,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION, | |
43 | COMMON_ARCH,__DATE__,__TIME__); | |
44 | ||
45 | // FIXME: generate from CommandLine | |
46 | c1out << | |
47 | _("Usage: apt [options] command\n" | |
48 | "\n" | |
49 | "CLI for apt.\n" | |
8a59cc32 | 50 | "Basic commands: \n" |
b9179170 MV |
51 | " list - list packages based on package names\n" |
52 | " search - search in package descriptions\n" | |
53 | " show - show package details\n" | |
54 | "\n" | |
55 | " update - update list of available packages\n" | |
8a59cc32 | 56 | "\n" |
b9179170 | 57 | " install - install packages\n" |
8a59cc32 MV |
58 | " remove - remove packages\n" |
59 | "\n" | |
59e81cec | 60 | " upgrade - upgrade the system by installing/upgrading packages\n" |
52090faa | 61 | " full-upgrade - upgrade the system by removing/installing/upgrading packages\n" |
cfacba52 MV |
62 | "\n" |
63 | " edit-sources - edit the source information file\n" | |
b9179170 MV |
64 | ); |
65 | ||
66 | return true; | |
67 | } | |
68 | ||
69 | int main(int argc, const char *argv[]) /*{{{*/ | |
70 | { | |
59e81cec MV |
71 | CommandLine::Dispatch Cmds[] = { |
72 | // query | |
ec4371ac | 73 | {"list",&DoList}, |
b9179170 MV |
74 | {"search", &FullTextSearch}, |
75 | {"show", &APT::Cmd::ShowPackage}, | |
59e81cec | 76 | |
6d73fe5b | 77 | // package stuff |
b9179170 MV |
78 | {"install",&DoInstall}, |
79 | {"remove", &DoInstall}, | |
8a59cc32 | 80 | {"purge", &DoInstall}, |
59e81cec | 81 | |
6d73fe5b | 82 | // system wide stuff |
b9179170 | 83 | {"update",&DoUpdate}, |
59e81cec MV |
84 | {"upgrade",&DoUpgrade}, |
85 | {"full-upgrade",&DoDistUpgrade}, | |
86 | // for compat with muscle memory | |
87 | {"dist-upgrade",&DoDistUpgrade}, | |
88 | ||
cfacba52 MV |
89 | // misc |
90 | {"edit-sources",&EditSources}, | |
59e81cec | 91 | |
b9179170 MV |
92 | // helper |
93 | {"moo",&DoMoo}, | |
94 | {"help",&ShowHelp}, | |
95 | {0,0}}; | |
96 | ||
97 | std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv)); | |
98 | ||
3163087b MV |
99 | // Init the signals |
100 | InitSignals(); | |
101 | ||
102 | // Init the output | |
b9179170 MV |
103 | InitOutput(); |
104 | ||
105 | // Set up gettext support | |
106 | setlocale(LC_ALL,""); | |
107 | textdomain(PACKAGE); | |
108 | ||
109 | if(pkgInitConfig(*_config) == false) | |
110 | { | |
111 | _error->DumpErrors(); | |
112 | return 100; | |
113 | } | |
114 | ||
59e81cec | 115 | // some different defaults |
8bc31a93 | 116 | _config->CndSet("DPkg::Progress-Fancy", "1"); |
59e81cec MV |
117 | _config->CndSet("Apt::Color", "1"); |
118 | _config->CndSet("APT::Get::Upgrade-Allow-New", true); | |
b9179170 MV |
119 | |
120 | // Parse the command line and initialize the package library | |
121 | CommandLine CmdL(Args.data(), _config); | |
122 | if (CmdL.Parse(argc, argv) == false || | |
123 | pkgInitSystem(*_config, _system) == false) | |
124 | { | |
125 | _error->DumpErrors(); | |
126 | return 100; | |
127 | } | |
128 | ||
14109555 MV |
129 | if(!isatty(STDOUT_FILENO) && |
130 | _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false) | |
131 | { | |
132 | std::cerr << std::endl | |
133 | << "WARNING: " << argv[0] << " " | |
134 | << "does not have a stable CLI interface yet. " | |
135 | << "Use with caution in scripts." | |
136 | << std::endl | |
137 | << std::endl; | |
138 | } | |
14109555 | 139 | |
b9179170 MV |
140 | // See if the help should be shown |
141 | if (_config->FindB("help") == true || | |
142 | _config->FindB("version") == true || | |
143 | CmdL.FileSize() == 0) | |
144 | { | |
145 | ShowHelp(CmdL); | |
146 | return 0; | |
147 | } | |
148 | ||
149 | // see if we are in simulate mode | |
150 | CheckSimulateMode(CmdL); | |
151 | ||
152 | // parse args | |
153 | CmdL.DispatchArg(Cmds); | |
154 | ||
155 | // Print any errors or warnings found during parsing | |
156 | bool const Errors = _error->PendingError(); | |
157 | if (_config->FindI("quiet",0) > 0) | |
158 | _error->DumpErrors(); | |
159 | else | |
160 | _error->DumpErrors(GlobalError::DEBUG); | |
161 | return Errors == true ? 100 : 0; | |
162 | } | |
163 | /*}}}*/ |