]>
git.saurik.com Git - apt.git/blob - apt-private/private-cmndline.cc
1 // Include Files /*{{{*/
4 #include <apt-pkg/cmndline.h>
6 #include <apt-private/private-cmndline.h>
15 APT_SENTINEL
static bool strcmp_match_in_list(char const * const Cmd
, ...) /*{{{*/
20 char const * Match
= NULL
;
21 while ((Match
= va_arg(args
, char const *)) != NULL
)
23 if (strcmp(Cmd
, Match
) != 0)
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)
34 static bool addArgumentsAPTCache(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
36 if (CmdMatches("depends", "rdepends", "xvcg", "dotty"))
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);
50 else if (CmdMatches("search"))
52 addArg('n', "names-only", "APT::Cache::NamesOnly", 0);
53 addArg('f', "full", "APT::Cache::ShowFull", 0);
55 else if (CmdMatches("show"))
57 addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
59 else if (CmdMatches("pkgnames"))
61 addArg(0, "all-names", "APT::Cache::AllNames", 0);
63 else if (CmdMatches("unmet"))
65 addArg('i', "important", "APT::Cache::Important", 0);
67 else if (CmdMatches("gencaches", "showsrc", "showpkg", "stats", "dump",
68 "dumpavail", "showauto", "policy", "madison"))
73 // FIXME: move to the correct command(s)
74 addArg('g', "generate", "APT::Cache::Generate", 0);
75 addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg
);
76 addArg('t', "default-release", "APT::Default-Release", CommandLine::HasArg
);
78 addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg
);
79 addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg
);
83 static bool addArgumentsAPTCDROM(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
85 if (CmdMatches("add", "ident") == false)
88 // FIXME: move to the correct command(s)
89 addArg(0, "auto-detect", "Acquire::cdrom::AutoDetect", CommandLine::Boolean
);
90 addArg('d', "cdrom", "Acquire::cdrom::mount", CommandLine::HasArg
);
91 addArg('r', "rename", "APT::CDROM::Rename", 0);
92 addArg('m', "no-mount", "APT::CDROM::NoMount", 0);
93 addArg('f', "fast", "APT::CDROM::Fast", 0);
94 addArg('n', "just-print", "APT::CDROM::NoAct", 0);
95 addArg('n', "recon", "APT::CDROM::NoAct", 0);
96 addArg('n', "no-act", "APT::CDROM::NoAct", 0);
97 addArg('a', "thorough", "APT::CDROM::Thorough", 0);
101 static bool addArgumentsAPTConfig(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
103 if (CmdMatches("dump"))
105 addArg(0,"empty","APT::Config::Dump::EmptyValue",CommandLine::Boolean
);
106 addArg(0,"format","APT::Config::Dump::Format",CommandLine::HasArg
);
108 else if (CmdMatches("shell"))
116 static bool addArgumentsAPTGet(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
118 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
119 "dselect-upgrade", "autoremove", "full-upgrade"))
121 addArg(0, "show-progress", "DpkgPM::Progress", 0);
122 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
123 addArg(0, "purge", "APT::Get::Purge", 0);
124 addArg('V',"verbose-versions","APT::Get::Show-Versions",0);
125 addArg(0, "auto-remove", "APT::Get::AutomaticRemove", 0);
126 addArg(0, "reinstall", "APT::Get::ReInstall", 0);
127 addArg(0, "solver", "APT::Solver", CommandLine::HasArg
);
128 if (CmdMatches("upgrade"))
130 addArg(0, "new-pkgs", "APT::Get::Upgrade-Allow-New",
131 CommandLine::Boolean
);
134 else if (CmdMatches("update"))
136 addArg(0, "list-cleanup", "APT::Get::List-Cleanup", 0);
138 else if (CmdMatches("source"))
140 addArg('b', "compile", "APT::Get::Compile", 0);
141 addArg('b', "build", "APT::Get::Compile", 0);
142 addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg
);
143 addArg(0, "diff-only", "APT::Get::Diff-Only", 0);
144 addArg(0, "debian-only", "APT::Get::Diff-Only", 0);
145 addArg(0, "tar-only", "APT::Get::Tar-Only", 0);
146 addArg(0, "dsc-only", "APT::Get::Dsc-Only", 0);
148 else if (CmdMatches("build-dep"))
150 addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg
);
151 addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg
);
152 addArg(0, "purge", "APT::Get::Purge", 0);
153 addArg(0, "solver", "APT::Solver", CommandLine::HasArg
);
154 // this has no effect *but* sbuild is using it (see LP: #1255806)
155 // once sbuild is fixed, this option can be removed
156 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
158 else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") ||
159 CmdMatches("markauto", "unmarkauto")) // deprecated commands
161 else if (CmdMatches("moo"))
162 addArg(0, "color", "APT::Moo::Color", 0);
164 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
165 "deselect-upgrade", "autoremove", "clean", "autoclean", "check",
166 "build-dep", "full-upgrade"))
168 addArg('s', "simulate", "APT::Get::Simulate", 0);
169 addArg('s', "just-print", "APT::Get::Simulate", 0);
170 addArg('s', "recon", "APT::Get::Simulate", 0);
171 addArg('s', "dry-run", "APT::Get::Simulate", 0);
172 addArg('s', "no-act", "APT::Get::Simulate", 0);
175 // FIXME: move to the correct command(s)
176 addArg('d',"download-only","APT::Get::Download-Only",0);
177 addArg('y',"yes","APT::Get::Assume-Yes",0);
178 addArg('y',"assume-yes","APT::Get::Assume-Yes",0);
179 addArg(0,"assume-no","APT::Get::Assume-No",0);
180 addArg('u',"show-upgraded","APT::Get::Show-Upgraded",0);
181 addArg('m',"ignore-missing","APT::Get::Fix-Missing",0);
182 addArg('t',"target-release","APT::Default-Release",CommandLine::HasArg
);
183 addArg('t',"default-release","APT::Default-Release",CommandLine::HasArg
);
184 addArg(0,"download","APT::Get::Download",0);
185 addArg(0,"fix-missing","APT::Get::Fix-Missing",0);
186 addArg(0,"ignore-hold","APT::Ignore-Hold",0);
187 addArg(0,"upgrade","APT::Get::upgrade",0);
188 addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0);
189 addArg(0,"force-yes","APT::Get::force-yes",0);
190 addArg(0,"print-uris","APT::Get::Print-URIs",0);
191 addArg(0,"trivial-only","APT::Get::Trivial-Only",0);
192 addArg(0,"remove","APT::Get::Remove",0);
193 addArg(0,"only-source","APT::Get::Only-Source",0);
194 addArg(0,"arch-only","APT::Get::Arch-Only",0);
195 addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0);
196 addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
);
197 addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean
);
198 addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
203 static bool addArgumentsAPTMark(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
205 if (CmdMatches("auto", "manual", "hold", "unhold", "showauto",
206 "showmanual", "showhold", "showholds", "install",
207 "markauto", "unmarkauto"))
212 addArg('v',"verbose","APT::MarkAuto::Verbose",0);
213 addArg('s',"simulate","APT::Mark::Simulate",0);
214 addArg('s',"just-print","APT::Mark::Simulate",0);
215 addArg('s',"recon","APT::Mark::Simulate",0);
216 addArg('s',"dry-run","APT::Mark::Simulate",0);
217 addArg('s',"no-act","APT::Mark::Simulate",0);
218 addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg
);
223 static bool addArgumentsAPT(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
225 if (CmdMatches("list"))
227 addArg(0,"installed","APT::Cmd::Installed",0);
228 addArg(0,"upgradable","APT::Cmd::Upgradable",0);
229 addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0);
230 addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0);
231 addArg('a', "all-versions", "APT::Cmd::All-Versions", 0);
233 else if (CmdMatches("show"))
235 addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
237 else if (addArgumentsAPTGet(Args
, Cmd
) || addArgumentsAPTCache(Args
, Cmd
))
239 // we have no (supported) command-name overlaps so far, so we call
240 // specifics in order until we find one which adds arguments
248 std::vector
<CommandLine::Args
> getCommandArgs(char const * const Program
, char const * const Cmd
)/*{{{*/
250 std::vector
<CommandLine::Args
> Args
;
252 if (Program
== NULL
|| Cmd
== NULL
)
253 ; // FIXME: Invalid command supplied
254 else if (strcmp(Cmd
, "help") == 0)
255 ; // no options for help so no need to implement it in each
256 else if (strcmp(Program
, "apt-get") == 0)
257 addArgumentsAPTGet(Args
, Cmd
);
258 else if (strcmp(Program
, "apt-cache") == 0)
259 addArgumentsAPTCache(Args
, Cmd
);
260 else if (strcmp(Program
, "apt-cdrom") == 0)
261 addArgumentsAPTCDROM(Args
, Cmd
);
262 else if (strcmp(Program
, "apt-config") == 0)
263 addArgumentsAPTConfig(Args
, Cmd
);
264 else if (strcmp(Program
, "apt-mark") == 0)
265 addArgumentsAPTMark(Args
, Cmd
);
266 else if (strcmp(Program
, "apt") == 0)
267 addArgumentsAPT(Args
, Cmd
);
269 // options without a command
270 addArg('h', "help", "help", 0);
271 addArg('v', "version", "version", 0);
273 addArg('q', "quiet", "quiet", CommandLine::IntLevel
);
274 addArg('q', "silent", "quiet", CommandLine::IntLevel
);
275 addArg('c', "config-file", 0, CommandLine::ConfigFile
);
276 addArg('o', "option", 0, CommandLine::ArbItem
);
277 addArg(0, NULL
, NULL
, 0);