]> git.saurik.com Git - apt.git/blame_incremental - cmdline/apt.cc
Merge branch 'debian/sid' into feature/more-fancy-progress
[apt.git] / cmdline / apt.cc
... / ...
CommitLineData
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
40static bool ShowHelp(CommandLine &)
41{
42 ioprintf(c1out,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
43 COMMON_ARCH,__DATE__,__TIME__);
44
45 // FIXME: generate from CommandLine
46 c1out <<
47 _("Usage: apt [options] command\n"
48 "\n"
49 "CLI for apt.\n"
50 "Basic commands: \n"
51 " list - list packages based on package names\n"
52 " search - search in package descriptions\n"
53 " show - show package details\n"
54 "\n"
55 " update - update list of available packages\n"
56 "\n"
57 " install - install packages\n"
58 " remove - remove 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
69int main(int argc, const char *argv[]) /*{{{*/
70{
71 CommandLine::Dispatch Cmds[] = {
72 // query
73 {"list",&List},
74 {"search", &FullTextSearch},
75 {"show", &APT::Cmd::ShowPackage},
76
77 // package stuff
78 {"install",&DoInstall},
79 {"remove", &DoInstall},
80 {"purge", &DoInstall},
81
82 // system wide stuff
83 {"update",&DoUpdate},
84 {"upgrade",&DoUpgrade},
85 {"full-upgrade",&DoDistUpgrade},
86 // for compat with muscle memory
87 {"dist-upgrade",&DoDistUpgrade},
88
89 // misc
90 {"edit-sources",&EditSources},
91
92 // helper
93 {"moo",&DoMoo},
94 {"help",&ShowHelp},
95 {0,0}};
96
97 std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
98
99 InitOutput();
100
101 // Set up gettext support
102 setlocale(LC_ALL,"");
103 textdomain(PACKAGE);
104
105 if(pkgInitConfig(*_config) == false)
106 {
107 _error->DumpErrors();
108 return 100;
109 }
110
111 // some different defaults
112 _config->CndSet("DPkgPM::Progress", "1");
113 _config->CndSet("Apt::Color", "1");
114 _config->CndSet("APT::Get::Upgrade-Allow-New", true);
115
116 // Parse the command line and initialize the package library
117 CommandLine CmdL(Args.data(), _config);
118 if (CmdL.Parse(argc, argv) == false ||
119 pkgInitSystem(*_config, _system) == false)
120 {
121 _error->DumpErrors();
122 return 100;
123 }
124
125 if(!isatty(STDOUT_FILENO) &&
126 _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
127 {
128 std::cerr << std::endl
129 << "WARNING: " << argv[0] << " "
130 << "does not have a stable CLI interface yet. "
131 << "Use with caution in scripts."
132 << std::endl
133 << std::endl;
134 }
135
136 // See if the help should be shown
137 if (_config->FindB("help") == true ||
138 _config->FindB("version") == true ||
139 CmdL.FileSize() == 0)
140 {
141 ShowHelp(CmdL);
142 return 0;
143 }
144
145 // see if we are in simulate mode
146 CheckSimulateMode(CmdL);
147
148 // parse args
149 CmdL.DispatchArg(Cmds);
150
151 // Print any errors or warnings found during parsing
152 bool const Errors = _error->PendingError();
153 if (_config->FindI("quiet",0) > 0)
154 _error->DumpErrors();
155 else
156 _error->DumpErrors(GlobalError::DEBUG);
157 return Errors == true ? 100 : 0;
158}
159 /*}}}*/