add new "apt-get upgrade --with-allow-new" option
[ntk/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 }
65 else if (CmdMatches("gencaches", "showsrc", "showpkg", "stats", "dump",
66 "dumpavail", "unmet", "showauto", "policy", "madison"))
67 ;
68 else
69 return false;
70
71 // FIXME: move to the correct command(s)
72 addArg('g', "generate", "APT::Cache::Generate", 0);
73 addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg);
74 addArg('t', "default-release", "APT::Default-Release", CommandLine::HasArg);
75
76 addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg);
77 addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg);
78 return true;
79}
80 /*}}}*/
81bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
82{
83 if (CmdMatches("add", "ident") == false)
84 return false;
85
86 // FIXME: move to the correct command(s)
87 addArg(0, "auto-detect", "Acquire::cdrom::AutoDetect", CommandLine::Boolean);
88 addArg('d', "cdrom", "Acquire::cdrom::mount", CommandLine::HasArg);
89 addArg('r', "rename", "APT::CDROM::Rename", 0);
90 addArg('m', "no-mount", "APT::CDROM::NoMount", 0);
91 addArg('f', "fast", "APT::CDROM::Fast", 0);
92 addArg('n', "just-print", "APT::CDROM::NoAct", 0);
93 addArg('n', "recon", "APT::CDROM::NoAct", 0);
94 addArg('n', "no-act", "APT::CDROM::NoAct", 0);
95 addArg('a', "thorough", "APT::CDROM::Thorough", 0);
96 return true;
97}
98 /*}}}*/
99bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
100{
101 if (CmdMatches("dump"))
102 {
103 addArg(0,"empty","APT::Config::Dump::EmptyValue",CommandLine::Boolean);
104 addArg(0,"format","APT::Config::Dump::Format",CommandLine::HasArg);
105 }
106 else if (CmdMatches("shell"))
107 ;
108 else
109 return false;
110
111 return true;
112}
113 /*}}}*/
114bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
115{
116 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
117 "deselect-upgrade", "autoremove"))
118 {
119 addArg(0, "dpkg-progress", "DpkgPM::Progress", 0);
120 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
121 addArg(0, "purge", "APT::Get::Purge", 0);
122 addArg('V',"verbose-versions","APT::Get::Show-Versions",0);
123 addArg(0, "auto-remove", "APT::Get::AutomaticRemove", 0);
124 addArg(0, "reinstall", "APT::Get::ReInstall", 0);
125 addArg(0, "solver", "APT::Solver", CommandLine::HasArg);
126 if (CmdMatches("upgrade"))
127 {
128 addArg(0, "allow-new", "APT::Get::UpgradeAllowNew", 0);
129 }
130 }
131 else if (CmdMatches("update"))
132 {
133 addArg(0, "list-cleanup", "APT::Get::List-Cleanup", 0);
134 }
135 else if (CmdMatches("source"))
136 {
137 addArg('b', "compile", "APT::Get::Compile", 0);
138 addArg('b', "build", "APT::Get::Compile", 0);
139 addArg(0, "diff-only", "APT::Get::Diff-Only", 0);
140 addArg(0, "debian-only", "APT::Get::Diff-Only", 0);
141 addArg(0, "tar-only", "APT::Get::Tar-Only", 0);
142 addArg(0, "dsc-only", "APT::Get::Dsc-Only", 0);
143 }
144 else if (CmdMatches("build-dep"))
145 {
146 addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg);
147 addArg(0, "solver", "APT::Solver", CommandLine::HasArg);
148 }
149 else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") ||
150 CmdMatches("markauto", "unmarkauto")) // deprecated commands
151 ;
152 else if (CmdMatches("moo"))
153 addArg(0, "color", "APT::Moo::Color", 0);
154
155 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
156 "deselect-upgrade", "autoremove", "clean", "autoclean", "check",
157 "build-dep"))
158 {
159 addArg('s', "simulate", "APT::Get::Simulate", 0);
160 addArg('s', "just-print", "APT::Get::Simulate", 0);
161 addArg('s', "recon", "APT::Get::Simulate", 0);
162 addArg('s', "dry-run", "APT::Get::Simulate", 0);
163 addArg('s', "no-act", "APT::Get::Simulate", 0);
164 }
165
c8d49419
MV
166 if (CmdMatches("upgrade"))
167 addArg(0, "allow-new", "APT::Get::UpgradeAllowNew", CommandLine::Boolean);
168
b9179170
MV
169 // FIXME: move to the correct command(s)
170 addArg('d',"download-only","APT::Get::Download-Only",0);
171 addArg('y',"yes","APT::Get::Assume-Yes",0);
172 addArg('y',"assume-yes","APT::Get::Assume-Yes",0);
173 addArg(0,"assume-no","APT::Get::Assume-No",0);
174 addArg('u',"show-upgraded","APT::Get::Show-Upgraded",0);
175 addArg('m',"ignore-missing","APT::Get::Fix-Missing",0);
176 addArg('t',"target-release","APT::Default-Release",CommandLine::HasArg);
177 addArg('t',"default-release","APT::Default-Release",CommandLine::HasArg);
178 addArg(0,"download","APT::Get::Download",0);
179 addArg(0,"fix-missing","APT::Get::Fix-Missing",0);
180 addArg(0,"ignore-hold","APT::Ignore-Hold",0);
181 addArg(0,"upgrade","APT::Get::upgrade",0);
182 addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0);
183 addArg(0,"force-yes","APT::Get::force-yes",0);
184 addArg(0,"print-uris","APT::Get::Print-URIs",0);
185 addArg(0,"trivial-only","APT::Get::Trivial-Only",0);
186 addArg(0,"remove","APT::Get::Remove",0);
187 addArg(0,"only-source","APT::Get::Only-Source",0);
188 addArg(0,"arch-only","APT::Get::Arch-Only",0);
189 addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0);
190 addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean);
191 addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean);
192 addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
193
194 return true;
195}
196 /*}}}*/
197bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
198{
199 if (CmdMatches("auto", "manual", "hold", "unhold", "showauto",
200 "showmanual", "showhold", "showholds", "install",
201 "markauto", "unmarkauto"))
202 ;
203 else
204 return false;
205
206 addArg('v',"verbose","APT::MarkAuto::Verbose",0);
207 addArg('s',"simulate","APT::Mark::Simulate",0);
208 addArg('s',"just-print","APT::Mark::Simulate",0);
209 addArg('s',"recon","APT::Mark::Simulate",0);
210 addArg('s',"dry-run","APT::Mark::Simulate",0);
211 addArg('s',"no-act","APT::Mark::Simulate",0);
212 addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg);
213
214 return true;
215}
216 /*}}}*/
217bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
218{
219 if (CmdMatches("list"))
220 {
221 addArg(0,"installed","APT::Cmd::Installed",0);
222 addArg(0,"upgradable","APT::Cmd::Upgradable",0);
223 addArg('a', "all-versions", "APT::Cmd::AllVersions", 0);
224 }
225 else if (addArgumentsAPTGet(Args, Cmd) || addArgumentsAPTCache(Args, Cmd))
226 {
227 // we have no (supported) command-name overlaps so far, so we call
228 // specifics in order until we find one which adds arguments
229 }
230 else
231 return false;
232
233 return true;
234}
235 /*}}}*/
236std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char const * const Cmd)/*{{{*/
237{
238 std::vector<CommandLine::Args> Args;
239 Args.reserve(50);
240 if (Program == NULL || Cmd == NULL)
241 ; // FIXME: Invalid command supplied
242 else if (strcmp(Cmd, "help") == 0)
243 ; // no options for help so no need to implement it in each
244 else if (strcmp(Program, "apt-get") == 0)
245 addArgumentsAPTGet(Args, Cmd);
246 else if (strcmp(Program, "apt-cache") == 0)
247 addArgumentsAPTCache(Args, Cmd);
248 else if (strcmp(Program, "apt-cdrom") == 0)
249 addArgumentsAPTCDROM(Args, Cmd);
250 else if (strcmp(Program, "apt-config") == 0)
251 addArgumentsAPTConfig(Args, Cmd);
252 else if (strcmp(Program, "apt-mark") == 0)
253 addArgumentsAPTMark(Args, Cmd);
254 else if (strcmp(Program, "apt") == 0)
255 addArgumentsAPT(Args, Cmd);
256
257 // options without a command
258 addArg('h', "help", "help", 0);
259 addArg('v', "version", "version", 0);
260 // general options
261 addArg('q', "quiet", "quiet", CommandLine::IntLevel);
262 addArg('q', "silent", "quiet", CommandLine::IntLevel);
263 addArg('c', "config-file", 0, CommandLine::ConfigFile);
264 addArg('o', "option", 0, CommandLine::ArbItem);
265 addArg(0, NULL, NULL, 0);
266
267 return Args;
268}
269 /*}}}*/
270#undef CmdMatches
271#undef addArg