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