]> git.saurik.com Git - apt.git/blame - apt-private/private-cmndline.cc
Merge branch 'debian/sid' into debian/experimental
[apt.git] / apt-private / private-cmndline.cc
CommitLineData
b9179170
MV
1// Include Files /*{{{*/
2#include <config.h>
3
4#include <apt-pkg/cmndline.h>
b9179170 5
453b82a3 6#include <apt-private/private-cmndline.h>
b9179170 7
453b82a3 8#include <vector>
b9179170
MV
9#include <stdarg.h>
10#include <string.h>
11
b9179170
MV
12#include <apti18n.h>
13 /*}}}*/
14
a02db58f 15APT_SENTINEL static bool strcmp_match_in_list(char const * const Cmd, ...) /*{{{*/
b9179170
MV
16{
17 va_list args;
18 bool found = false;
19 va_start(args, Cmd);
20 char const * Match = NULL;
21 while ((Match = va_arg(args, char const *)) != NULL)
22 {
23 if (strcmp(Cmd, Match) != 0)
24 continue;
25 found = true;
26 break;
27 }
28 va_end(args);
29 return found;
30}
31 /*}}}*/
32#define addArg(w,x,y,z) Args.push_back(CommandLine::MakeArgs(w,x,y,z))
33#define CmdMatches(...) strcmp_match_in_list(Cmd, __VA_ARGS__, NULL)
c3ccac92 34static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
b9179170
MV
35{
36 if (CmdMatches("depends", "rdepends", "xvcg", "dotty"))
37 {
38 addArg('i', "important", "APT::Cache::Important", 0);
39 addArg(0, "installed", "APT::Cache::Installed", 0);
40 addArg(0, "pre-depends", "APT::Cache::ShowPre-Depends", 0);
41 addArg(0, "depends", "APT::Cache::ShowDepends", 0);
42 addArg(0, "recommends", "APT::Cache::ShowRecommends", 0);
43 addArg(0, "suggests", "APT::Cache::ShowSuggests", 0);
44 addArg(0, "replaces", "APT::Cache::ShowReplaces", 0);
45 addArg(0, "breaks", "APT::Cache::ShowBreaks", 0);
46 addArg(0, "conflicts", "APT::Cache::ShowConflicts", 0);
47 addArg(0, "enhances", "APT::Cache::ShowEnhances", 0);
48 addArg(0, "recurse", "APT::Cache::RecurseDepends", 0);
49 }
50 else if (CmdMatches("search"))
51 {
52 addArg('n', "names-only", "APT::Cache::NamesOnly", 0);
53 addArg('f', "full", "APT::Cache::ShowFull", 0);
54 }
55 else if (CmdMatches("show"))
56 {
57 addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
58 }
59 else if (CmdMatches("pkgnames"))
60 {
61 addArg(0, "all-names", "APT::Cache::AllNames", 0);
62 }
58c2833f
MV
63 else if (CmdMatches("unmet"))
64 {
65 addArg('i', "important", "APT::Cache::Important", 0);
66 }
b9179170 67 else if (CmdMatches("gencaches", "showsrc", "showpkg", "stats", "dump",
58c2833f 68 "dumpavail", "showauto", "policy", "madison"))
b9179170
MV
69 ;
70 else
71 return false;
72
859093da
DK
73 bool const found_something = Args.empty() == false;
74
b9179170
MV
75 // FIXME: move to the correct command(s)
76 addArg('g', "generate", "APT::Cache::Generate", 0);
77 addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg);
78 addArg('t', "default-release", "APT::Default-Release", CommandLine::HasArg);
79
80 addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg);
81 addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg);
859093da
DK
82
83 return found_something;
b9179170
MV
84}
85 /*}}}*/
c3ccac92 86static bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
b9179170
MV
87{
88 if (CmdMatches("add", "ident") == false)
89 return false;
90
91 // FIXME: move to the correct command(s)
92 addArg(0, "auto-detect", "Acquire::cdrom::AutoDetect", CommandLine::Boolean);
93 addArg('d', "cdrom", "Acquire::cdrom::mount", CommandLine::HasArg);
94 addArg('r', "rename", "APT::CDROM::Rename", 0);
95 addArg('m', "no-mount", "APT::CDROM::NoMount", 0);
96 addArg('f', "fast", "APT::CDROM::Fast", 0);
97 addArg('n', "just-print", "APT::CDROM::NoAct", 0);
98 addArg('n', "recon", "APT::CDROM::NoAct", 0);
99 addArg('n', "no-act", "APT::CDROM::NoAct", 0);
100 addArg('a', "thorough", "APT::CDROM::Thorough", 0);
101 return true;
102}
103 /*}}}*/
c3ccac92 104static bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
b9179170
MV
105{
106 if (CmdMatches("dump"))
107 {
108 addArg(0,"empty","APT::Config::Dump::EmptyValue",CommandLine::Boolean);
109 addArg(0,"format","APT::Config::Dump::Format",CommandLine::HasArg);
110 }
111 else if (CmdMatches("shell"))
112 ;
113 else
114 return false;
115
116 return true;
117}
118 /*}}}*/
c3ccac92 119static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
b9179170
MV
120{
121 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
ebe24b7a 122 "dselect-upgrade", "autoremove", "full-upgrade"))
b9179170 123 {
4fb66d87 124 addArg(0, "show-progress", "DpkgPM::Progress", 0);
b9179170
MV
125 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
126 addArg(0, "purge", "APT::Get::Purge", 0);
127 addArg('V',"verbose-versions","APT::Get::Show-Versions",0);
128 addArg(0, "auto-remove", "APT::Get::AutomaticRemove", 0);
129 addArg(0, "reinstall", "APT::Get::ReInstall", 0);
130 addArg(0, "solver", "APT::Solver", CommandLine::HasArg);
131 if (CmdMatches("upgrade"))
132 {
2004d647 133 addArg(0, "new-pkgs", "APT::Get::Upgrade-Allow-New",
c678a044 134 CommandLine::Boolean);
b9179170
MV
135 }
136 }
137 else if (CmdMatches("update"))
138 {
139 addArg(0, "list-cleanup", "APT::Get::List-Cleanup", 0);
140 }
141 else if (CmdMatches("source"))
142 {
143 addArg('b', "compile", "APT::Get::Compile", 0);
144 addArg('b', "build", "APT::Get::Compile", 0);
ce7f128c 145 addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg);
b9179170
MV
146 addArg(0, "diff-only", "APT::Get::Diff-Only", 0);
147 addArg(0, "debian-only", "APT::Get::Diff-Only", 0);
148 addArg(0, "tar-only", "APT::Get::Tar-Only", 0);
149 addArg(0, "dsc-only", "APT::Get::Dsc-Only", 0);
150 }
151 else if (CmdMatches("build-dep"))
152 {
153 addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg);
ce7f128c 154 addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg);
e4e5d47b 155 addArg(0, "purge", "APT::Get::Purge", 0);
b9179170 156 addArg(0, "solver", "APT::Solver", CommandLine::HasArg);
c872ac50
MV
157 // this has no effect *but* sbuild is using it (see LP: #1255806)
158 // once sbuild is fixed, this option can be removed
159 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
b9179170
MV
160 }
161 else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") ||
162 CmdMatches("markauto", "unmarkauto")) // deprecated commands
163 ;
164 else if (CmdMatches("moo"))
165 addArg(0, "color", "APT::Moo::Color", 0);
166
167 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
168 "deselect-upgrade", "autoremove", "clean", "autoclean", "check",
ebe24b7a 169 "build-dep", "full-upgrade"))
b9179170
MV
170 {
171 addArg('s', "simulate", "APT::Get::Simulate", 0);
172 addArg('s', "just-print", "APT::Get::Simulate", 0);
173 addArg('s', "recon", "APT::Get::Simulate", 0);
174 addArg('s', "dry-run", "APT::Get::Simulate", 0);
175 addArg('s', "no-act", "APT::Get::Simulate", 0);
176 }
177
859093da
DK
178 bool const found_something = Args.empty() == false;
179
b9179170
MV
180 // FIXME: move to the correct command(s)
181 addArg('d',"download-only","APT::Get::Download-Only",0);
182 addArg('y',"yes","APT::Get::Assume-Yes",0);
183 addArg('y',"assume-yes","APT::Get::Assume-Yes",0);
184 addArg(0,"assume-no","APT::Get::Assume-No",0);
185 addArg('u',"show-upgraded","APT::Get::Show-Upgraded",0);
186 addArg('m',"ignore-missing","APT::Get::Fix-Missing",0);
187 addArg('t',"target-release","APT::Default-Release",CommandLine::HasArg);
188 addArg('t',"default-release","APT::Default-Release",CommandLine::HasArg);
189 addArg(0,"download","APT::Get::Download",0);
190 addArg(0,"fix-missing","APT::Get::Fix-Missing",0);
191 addArg(0,"ignore-hold","APT::Ignore-Hold",0);
192 addArg(0,"upgrade","APT::Get::upgrade",0);
193 addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0);
194 addArg(0,"force-yes","APT::Get::force-yes",0);
195 addArg(0,"print-uris","APT::Get::Print-URIs",0);
196 addArg(0,"trivial-only","APT::Get::Trivial-Only",0);
197 addArg(0,"remove","APT::Get::Remove",0);
198 addArg(0,"only-source","APT::Get::Only-Source",0);
199 addArg(0,"arch-only","APT::Get::Arch-Only",0);
200 addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0);
c99fe2e1 201 addArg(0,"allow-insecure-repositories","Acquire::AllowInsecureRepositories",0);
b9179170
MV
202 addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean);
203 addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean);
204 addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
205
859093da 206 return found_something;
b9179170
MV
207}
208 /*}}}*/
c3ccac92 209static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
b9179170
MV
210{
211 if (CmdMatches("auto", "manual", "hold", "unhold", "showauto",
212 "showmanual", "showhold", "showholds", "install",
213 "markauto", "unmarkauto"))
214 ;
215 else
216 return false;
217
218 addArg('v',"verbose","APT::MarkAuto::Verbose",0);
219 addArg('s',"simulate","APT::Mark::Simulate",0);
220 addArg('s',"just-print","APT::Mark::Simulate",0);
221 addArg('s',"recon","APT::Mark::Simulate",0);
222 addArg('s',"dry-run","APT::Mark::Simulate",0);
223 addArg('s',"no-act","APT::Mark::Simulate",0);
224 addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg);
225
226 return true;
227}
228 /*}}}*/
c3ccac92 229static bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
b9179170
MV
230{
231 if (CmdMatches("list"))
232 {
233 addArg(0,"installed","APT::Cmd::Installed",0);
234 addArg(0,"upgradable","APT::Cmd::Upgradable",0);
3bdf7da5 235 addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0);
e1dc051a 236 addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0);
c1a61d1c 237 addArg('a', "all-versions", "APT::Cmd::All-Versions", 0);
b9179170 238 }
06293aa7
MV
239 else if (CmdMatches("show"))
240 {
241 addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
242 }
b9179170
MV
243 else if (addArgumentsAPTGet(Args, Cmd) || addArgumentsAPTCache(Args, Cmd))
244 {
245 // we have no (supported) command-name overlaps so far, so we call
246 // specifics in order until we find one which adds arguments
247 }
248 else
249 return false;
250
251 return true;
252}
253 /*}}}*/
254std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char const * const Cmd)/*{{{*/
255{
256 std::vector<CommandLine::Args> Args;
257 Args.reserve(50);
258 if (Program == NULL || Cmd == NULL)
259 ; // FIXME: Invalid command supplied
260 else if (strcmp(Cmd, "help") == 0)
261 ; // no options for help so no need to implement it in each
262 else if (strcmp(Program, "apt-get") == 0)
263 addArgumentsAPTGet(Args, Cmd);
264 else if (strcmp(Program, "apt-cache") == 0)
265 addArgumentsAPTCache(Args, Cmd);
266 else if (strcmp(Program, "apt-cdrom") == 0)
267 addArgumentsAPTCDROM(Args, Cmd);
268 else if (strcmp(Program, "apt-config") == 0)
269 addArgumentsAPTConfig(Args, Cmd);
270 else if (strcmp(Program, "apt-mark") == 0)
271 addArgumentsAPTMark(Args, Cmd);
272 else if (strcmp(Program, "apt") == 0)
273 addArgumentsAPT(Args, Cmd);
274
275 // options without a command
276 addArg('h', "help", "help", 0);
277 addArg('v', "version", "version", 0);
278 // general options
279 addArg('q', "quiet", "quiet", CommandLine::IntLevel);
280 addArg('q', "silent", "quiet", CommandLine::IntLevel);
281 addArg('c', "config-file", 0, CommandLine::ConfigFile);
282 addArg('o', "option", 0, CommandLine::ArbItem);
283 addArg(0, NULL, NULL, 0);
284
285 return Args;
286}
287 /*}}}*/
288#undef CmdMatches
289#undef addArg