]> git.saurik.com Git - apt.git/blob - cmdline/apt.cc
Provide "apt-get full-upgrade" to match "apt full-upgrade"
[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
33 #include <unistd.h>
34 #include <iostream>
35 #include <vector>
36
37 #include <apti18n.h>
38 /*}}}*/
39
40 static bool ShowHelp(CommandLine &)
41 {
42 ioprintf(c1out, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
43
44 // FIXME: generate from CommandLine
45 c1out <<
46 _("Usage: apt [options] command\n"
47 "\n"
48 "CLI for apt.\n"
49 "Basic commands: \n"
50 " list - list packages based on package names\n"
51 " search - search in package descriptions\n"
52 " show - show package details\n"
53 "\n"
54 " update - update list of available packages\n"
55 "\n"
56 " install - install packages\n"
57 " remove - remove packages\n"
58 " autoremove - Remove automatically all unused packages\n"
59 "\n"
60 " upgrade - upgrade the system by installing/upgrading packages\n"
61 " full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
62 "\n"
63 " edit-sources - edit the source information file\n"
64 );
65
66 return true;
67 }
68
69 int main(int argc, const char *argv[]) /*{{{*/
70 {
71 CommandLine::Dispatch Cmds[] = {
72 // query
73 {"list",&DoList},
74 {"search", &FullTextSearch},
75 {"show", &APT::Cmd::ShowPackage},
76
77 // package stuff
78 {"install",&DoInstall},
79 {"remove", &DoInstall},
80 {"autoremove", &DoInstall},
81 {"auto-remove", &DoInstall},
82 {"purge", &DoInstall},
83
84 // system wide stuff
85 {"update",&DoUpdate},
86 {"upgrade",&DoUpgrade},
87 {"full-upgrade",&DoDistUpgrade},
88 // for compat with muscle memory
89 {"dist-upgrade",&DoDistUpgrade},
90
91 // misc
92 {"edit-sources",&EditSources},
93
94 // helper
95 {"moo",&DoMoo},
96 {"help",&ShowHelp},
97 {0,0}};
98
99 std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
100
101 // Init the signals
102 InitSignals();
103
104 // Init the output
105 InitOutput();
106
107 // Set up gettext support
108 setlocale(LC_ALL,"");
109 textdomain(PACKAGE);
110
111 if(pkgInitConfig(*_config) == false)
112 {
113 _error->DumpErrors();
114 return 100;
115 }
116
117 // some different defaults
118 _config->CndSet("DPkg::Progress-Fancy", "1");
119 _config->CndSet("Apt::Color", "1");
120 _config->CndSet("APT::Get::Upgrade-Allow-New", true);
121 _config->CndSet("APT::Cmd::Show-Update-Stats", true);
122
123 // Parse the command line and initialize the package library
124 CommandLine CmdL;
125 ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
126
127 if(!isatty(STDOUT_FILENO) &&
128 _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
129 {
130 std::cerr << std::endl
131 << "WARNING: " << argv[0] << " "
132 << "does not have a stable CLI interface yet. "
133 << "Use with caution in scripts."
134 << std::endl
135 << std::endl;
136 }
137
138 // see if we are in simulate mode
139 CheckSimulateMode(CmdL);
140
141 // parse args
142 CmdL.DispatchArg(Cmds);
143
144 // Print any errors or warnings found during parsing
145 bool const Errors = _error->PendingError();
146 if (_config->FindI("quiet",0) > 0)
147 _error->DumpErrors();
148 else
149 _error->DumpErrors(GlobalError::DEBUG);
150 return Errors == true ? 100 : 0;
151 }
152 /*}}}*/