]> git.saurik.com Git - apt.git/blame - cmdline/apt.cc
improve apt.8.xml
[apt.git] / cmdline / apt.cc
CommitLineData
b9179170
MV
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 <cassert>
15#include <locale.h>
16#include <iostream>
17#include <unistd.h>
18#include <errno.h>
19#include <regex.h>
20#include <stdio.h>
21#include <iomanip>
22#include <algorithm>
23
24
25#include <apt-pkg/error.h>
26#include <apt-pkg/cachefile.h>
27#include <apt-pkg/cacheset.h>
28#include <apt-pkg/init.h>
29#include <apt-pkg/progress.h>
30#include <apt-pkg/sourcelist.h>
31#include <apt-pkg/cmndline.h>
32#include <apt-pkg/strutl.h>
33#include <apt-pkg/fileutl.h>
34#include <apt-pkg/pkgrecords.h>
35#include <apt-pkg/srcrecords.h>
36#include <apt-pkg/version.h>
37#include <apt-pkg/policy.h>
38#include <apt-pkg/tagfile.h>
39#include <apt-pkg/algorithms.h>
40#include <apt-pkg/sptr.h>
41#include <apt-pkg/pkgsystem.h>
42#include <apt-pkg/indexfile.h>
43#include <apt-pkg/metaindex.h>
e6645b9f 44#include <apt-pkg/hashes.h>
b9179170
MV
45
46#include <apti18n.h>
47
48#include <apt-private/private-list.h>
49#include <apt-private/private-search.h>
50#include <apt-private/private-install.h>
51#include <apt-private/private-output.h>
52#include <apt-private/private-update.h>
53#include <apt-private/private-cmndline.h>
54#include <apt-private/private-moo.h>
55#include <apt-private/private-upgrade.h>
56#include <apt-private/private-show.h>
57#include <apt-private/private-main.h>
cfacba52 58#include <apt-private/private-utils.h>
9e6b13f3 59#include <apt-private/private-sources.h>
b9179170
MV
60 /*}}}*/
61
cfacba52
MV
62
63
b9179170
MV
64bool ShowHelp(CommandLine &CmdL)
65{
66 ioprintf(c1out,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
67 COMMON_ARCH,__DATE__,__TIME__);
68
69 // FIXME: generate from CommandLine
70 c1out <<
71 _("Usage: apt [options] command\n"
72 "\n"
73 "CLI for apt.\n"
74 "Commands: \n"
75 " list - list packages based on package names\n"
76 " search - search in package descriptions\n"
77 " show - show package details\n"
78 "\n"
b9179170 79 " install - install packages\n"
132a7f88 80 " remove - remove packages\n"
cfacba52
MV
81 "\n"
82 " edit-sources - edit the source information file\n"
259d88d9
MV
83 "\n"
84 " update - update list of available packages\n"
85 " upgrade - upgrade the systems packages\n"
b9179170
MV
86 );
87
88 return true;
89}
90
91int main(int argc, const char *argv[]) /*{{{*/
92{
93 CommandLine::Dispatch Cmds[] = {{"list",&List},
94 {"search", &FullTextSearch},
95 {"show", &APT::Cmd::ShowPackage},
96 // needs root
97 {"install",&DoInstall},
98 {"remove", &DoInstall},
99 {"update",&DoUpdate},
100 {"upgrade",&DoUpgradeWithAllowNewPackages},
cfacba52
MV
101 // misc
102 {"edit-sources",&EditSources},
b9179170
MV
103 // helper
104 {"moo",&DoMoo},
105 {"help",&ShowHelp},
106 {0,0}};
107
108 std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
109
110 if(!isatty(1))
111 {
112 std::cerr << std::endl
113 << "WARNING WARNING "
114 << argv[0]
115 << " is *NOT* intended for scripts "
116 << "use at your own peril^Wrisk"
117 << std::endl
118 << std::endl;
119 }
120
121 InitOutput();
122
123 // Set up gettext support
124 setlocale(LC_ALL,"");
125 textdomain(PACKAGE);
126
127 if(pkgInitConfig(*_config) == false)
128 {
129 _error->DumpErrors();
130 return 100;
131 }
132
133 // FIXME: move into a new libprivate/private-install.cc:Install()
81d18368 134 _config->Set("DPkgPM::Progress-Fancy", "1");
b9179170
MV
135 _config->Set("Apt::Color", "1");
136
137 // Parse the command line and initialize the package library
138 CommandLine CmdL(Args.data(), _config);
139 if (CmdL.Parse(argc, argv) == false ||
140 pkgInitSystem(*_config, _system) == false)
141 {
142 _error->DumpErrors();
143 return 100;
144 }
145
146 // See if the help should be shown
147 if (_config->FindB("help") == true ||
148 _config->FindB("version") == true ||
149 CmdL.FileSize() == 0)
150 {
151 ShowHelp(CmdL);
152 return 0;
153 }
154
155 // see if we are in simulate mode
156 CheckSimulateMode(CmdL);
157
158 // parse args
159 CmdL.DispatchArg(Cmds);
160
161 // Print any errors or warnings found during parsing
162 bool const Errors = _error->PendingError();
163 if (_config->FindI("quiet",0) > 0)
164 _error->DumpErrors();
165 else
166 _error->DumpErrors(GlobalError::DEBUG);
167 return Errors == true ? 100 : 0;
168}
169 /*}}}*/