]> git.saurik.com Git - apt.git/blob - cmdline/apt.cc
368822d2d7d53009c049c91285be58e159ae0f2d
[apt.git] / cmdline / apt.cc
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 <apt-pkg/cmndline.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/init.h>
17 #include <apt-pkg/pkgsystem.h>
18 #include <apt-pkg/strutl.h>
19 #include <apt-pkg/configuration.h>
20
21 #include <apt-private/private-list.h>
22 #include <apt-private/private-search.h>
23 #include <apt-private/private-install.h>
24 #include <apt-private/private-output.h>
25 #include <apt-private/private-update.h>
26 #include <apt-private/private-cmndline.h>
27 #include <apt-private/private-moo.h>
28 #include <apt-private/private-upgrade.h>
29 #include <apt-private/private-show.h>
30 #include <apt-private/private-main.h>
31 #include <apt-private/private-sources.h>
32 #include <apt-private/private-source.h>
33 #include <apt-private/private-depends.h>
34 #include <apt-private/private-download.h>
35
36 #include <unistd.h>
37 #include <iostream>
38 #include <vector>
39
40 #include <apti18n.h>
41 /*}}}*/
42
43 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/
44 {
45 std::cout <<
46 _("Usage: apt [options] command\n"
47 "\n"
48 "CLI for apt.\n")
49 << std::endl;
50 ShowHelpListCommands(Cmds);
51 return true;
52 }
53 /*}}}*/
54 std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
55 {
56 return {
57 // query
58 {"list", &DoList, _("list packages based on package names")},
59 {"search", &DoSearch, _("search in package descriptions")},
60 {"show", &ShowPackage, _("show package details")},
61
62 // package stuff
63 {"install", &DoInstall, _("install packages")},
64 {"remove", &DoInstall, _("remove packages")},
65 {"autoremove", &DoInstall, _("Remove automatically all unused packages")},
66 {"auto-remove", &DoInstall, nullptr},
67 {"purge", &DoInstall, nullptr},
68
69 // system wide stuff
70 {"update", &DoUpdate, _("update list of available packages")},
71 {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")},
72 {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")},
73
74 // misc
75 {"edit-sources", &EditSources, _("edit the source information file")},
76 {"moo", &DoMoo, nullptr},
77
78 // for compat with muscle memory
79 {"dist-upgrade", &DoDistUpgrade, nullptr},
80 {"showsrc",&ShowSrcPackage, nullptr},
81 {"depends",&Depends, nullptr},
82 {"rdepends",&RDepends, nullptr},
83 {"policy",&Policy, nullptr},
84 {"build-dep", &DoBuildDep,nullptr},
85 {"clean", &DoClean, nullptr},
86 {"autoclean", &DoAutoClean, nullptr},
87 {"auto-clean", &DoAutoClean, nullptr},
88 {"source", &DoSource, nullptr},
89 {"download", &DoDownload, nullptr},
90 {"changelog", &DoChangelog, nullptr},
91
92 {nullptr, nullptr, nullptr}
93 };
94 }
95 /*}}}*/
96 int main(int argc, const char *argv[]) /*{{{*/
97 {
98 InitLocale();
99
100 CommandLine CmdL;
101 auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv);
102
103 int const quiet = _config->FindI("quiet", 0);
104 if (quiet == 2)
105 {
106 _config->CndSet("quiet::NoProgress", true);
107 _config->Set("quiet", 1);
108 }
109
110 InitSignals();
111 InitOutput();
112
113 CheckIfCalledByScript(argc, argv);
114 CheckIfSimulateMode(CmdL);
115
116 return DispatchCommandLine(CmdL, Cmds);
117 }
118 /*}}}*/