]>
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 | ||
14 | #include <cassert> | |
15 | #include <locale.h> | |
16 | #include <iostream> | |
17 | #include <unistd.h> | |
18 | #include <errno.h> | |
19 | #include <regex.h> | |
20 | #include <stdio.h> | |
21 | #include <iomanip> | |
22 | #include <algorithm> | |
23 | ||
24 | ||
25 | #include <apt-pkg/error.h> | |
26 | #include <apt-pkg/cachefile.h> | |
27 | #include <apt-pkg/cacheset.h> | |
28 | #include <apt-pkg/init.h> | |
29 | #include <apt-pkg/progress.h> | |
30 | #include <apt-pkg/sourcelist.h> | |
31 | #include <apt-pkg/cmndline.h> | |
32 | #include <apt-pkg/strutl.h> | |
33 | #include <apt-pkg/fileutl.h> | |
34 | #include <apt-pkg/pkgrecords.h> | |
35 | #include <apt-pkg/srcrecords.h> | |
36 | #include <apt-pkg/version.h> | |
37 | #include <apt-pkg/policy.h> | |
38 | #include <apt-pkg/tagfile.h> | |
39 | #include <apt-pkg/algorithms.h> | |
40 | #include <apt-pkg/sptr.h> | |
41 | #include <apt-pkg/pkgsystem.h> | |
42 | #include <apt-pkg/indexfile.h> | |
43 | #include <apt-pkg/metaindex.h> | |
e6645b9f | 44 | #include <apt-pkg/hashes.h> |
b9179170 MV |
45 | |
46 | #include <apti18n.h> | |
47 | ||
48 | #include <apt-private/private-list.h> | |
49 | #include <apt-private/private-search.h> | |
50 | #include <apt-private/private-install.h> | |
51 | #include <apt-private/private-output.h> | |
52 | #include <apt-private/private-update.h> | |
53 | #include <apt-private/private-cmndline.h> | |
54 | #include <apt-private/private-moo.h> | |
55 | #include <apt-private/private-upgrade.h> | |
56 | #include <apt-private/private-show.h> | |
57 | #include <apt-private/private-main.h> | |
cfacba52 | 58 | #include <apt-private/private-utils.h> |
9e6b13f3 | 59 | #include <apt-private/private-sources.h> |
b9179170 MV |
60 | /*}}}*/ |
61 | ||
cfacba52 MV |
62 | |
63 | ||
b9179170 MV |
64 | bool ShowHelp(CommandLine &CmdL) |
65 | { | |
66 | ioprintf(c1out,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION, | |
67 | COMMON_ARCH,__DATE__,__TIME__); | |
68 | ||
69 | // FIXME: generate from CommandLine | |
70 | c1out << | |
71 | _("Usage: apt [options] command\n" | |
72 | "\n" | |
73 | "CLI for apt.\n" | |
8a59cc32 | 74 | "Basic commands: \n" |
b9179170 MV |
75 | " list - list packages based on package names\n" |
76 | " search - search in package descriptions\n" | |
77 | " show - show package details\n" | |
78 | "\n" | |
79 | " update - update list of available packages\n" | |
8a59cc32 | 80 | "\n" |
b9179170 | 81 | " install - install packages\n" |
8a59cc32 MV |
82 | " remove - remove packages\n" |
83 | "\n" | |
b9179170 | 84 | " upgrade - upgrade the systems packages\n" |
cfacba52 MV |
85 | "\n" |
86 | " edit-sources - edit the source information file\n" | |
b9179170 MV |
87 | ); |
88 | ||
89 | return true; | |
90 | } | |
91 | ||
82e7f817 MV |
92 | // figure out what kind of upgrade the user wants |
93 | bool DoAptUpgrade(CommandLine &CmdL) | |
94 | { | |
95 | if (_config->FindB("Apt::Cmd::Dist-Upgrade")) | |
96 | return DoDistUpgrade(CmdL); | |
97 | else | |
98 | return DoUpgradeWithAllowNewPackages(CmdL); | |
99 | } | |
100 | ||
b9179170 MV |
101 | int main(int argc, const char *argv[]) /*{{{*/ |
102 | { | |
103 | CommandLine::Dispatch Cmds[] = {{"list",&List}, | |
104 | {"search", &FullTextSearch}, | |
105 | {"show", &APT::Cmd::ShowPackage}, | |
6d73fe5b | 106 | // package stuff |
b9179170 MV |
107 | {"install",&DoInstall}, |
108 | {"remove", &DoInstall}, | |
8a59cc32 | 109 | {"purge", &DoInstall}, |
6d73fe5b | 110 | // system wide stuff |
b9179170 | 111 | {"update",&DoUpdate}, |
82e7f817 | 112 | {"upgrade",&DoAptUpgrade}, |
cfacba52 MV |
113 | // misc |
114 | {"edit-sources",&EditSources}, | |
b9179170 MV |
115 | // helper |
116 | {"moo",&DoMoo}, | |
117 | {"help",&ShowHelp}, | |
118 | {0,0}}; | |
119 | ||
120 | std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv)); | |
121 | ||
b9179170 MV |
122 | InitOutput(); |
123 | ||
124 | // Set up gettext support | |
125 | setlocale(LC_ALL,""); | |
126 | textdomain(PACKAGE); | |
127 | ||
128 | if(pkgInitConfig(*_config) == false) | |
129 | { | |
130 | _error->DumpErrors(); | |
131 | return 100; | |
132 | } | |
133 | ||
134 | // FIXME: move into a new libprivate/private-install.cc:Install() | |
135 | _config->Set("DPkgPM::Progress", "1"); | |
136 | _config->Set("Apt::Color", "1"); | |
137 | ||
138 | // Parse the command line and initialize the package library | |
139 | CommandLine CmdL(Args.data(), _config); | |
140 | if (CmdL.Parse(argc, argv) == false || | |
141 | pkgInitSystem(*_config, _system) == false) | |
142 | { | |
143 | _error->DumpErrors(); | |
144 | return 100; | |
145 | } | |
146 | ||
14109555 MV |
147 | if(!isatty(STDOUT_FILENO) && |
148 | _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false) | |
149 | { | |
150 | std::cerr << std::endl | |
151 | << "WARNING: " << argv[0] << " " | |
152 | << "does not have a stable CLI interface yet. " | |
153 | << "Use with caution in scripts." | |
154 | << std::endl | |
155 | << std::endl; | |
156 | } | |
157 | if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) | |
158 | _config->Set("quiet","1"); | |
159 | ||
b9179170 MV |
160 | // See if the help should be shown |
161 | if (_config->FindB("help") == true || | |
162 | _config->FindB("version") == true || | |
163 | CmdL.FileSize() == 0) | |
164 | { | |
165 | ShowHelp(CmdL); | |
166 | return 0; | |
167 | } | |
168 | ||
169 | // see if we are in simulate mode | |
170 | CheckSimulateMode(CmdL); | |
171 | ||
172 | // parse args | |
173 | CmdL.DispatchArg(Cmds); | |
174 | ||
175 | // Print any errors or warnings found during parsing | |
176 | bool const Errors = _error->PendingError(); | |
177 | if (_config->FindI("quiet",0) > 0) | |
178 | _error->DumpErrors(); | |
179 | else | |
180 | _error->DumpErrors(GlobalError::DEBUG); | |
181 | return Errors == true ? 100 : 0; | |
182 | } | |
183 | /*}}}*/ |