]> git.saurik.com Git - apt.git/blame - cmdline/apt.cc
disable updating insecure repositories in apt by default
[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
453b82a3 14#include <apt-pkg/cmndline.h>
b9179170 15#include <apt-pkg/error.h>
b9179170 16#include <apt-pkg/init.h>
b9179170 17#include <apt-pkg/pkgsystem.h>
453b82a3
DK
18#include <apt-pkg/strutl.h>
19#include <apt-pkg/configuration.h>
b9179170
MV
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>
9e6b13f3 31#include <apt-private/private-sources.h>
b9179170 32
453b82a3
DK
33#include <unistd.h>
34#include <iostream>
35#include <vector>
cfacba52 36
453b82a3
DK
37#include <apti18n.h>
38 /*}}}*/
cfacba52 39
65512241 40static bool ShowHelp(CommandLine &)
b9179170 41{
249aec3b 42 ioprintf(c1out, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
b9179170
MV
43
44 // FIXME: generate from CommandLine
45 c1out <<
46 _("Usage: apt [options] command\n"
47 "\n"
48 "CLI for apt.\n"
8a59cc32 49 "Basic commands: \n"
b9179170
MV
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"
8a59cc32 55 "\n"
b9179170 56 " install - install packages\n"
8a59cc32 57 " remove - remove packages\n"
825220b5 58 " autoremove - Remove automatically all unused packages\n"
8a59cc32 59 "\n"
59e81cec 60 " upgrade - upgrade the system by installing/upgrading packages\n"
52090faa 61 " full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
cfacba52
MV
62 "\n"
63 " edit-sources - edit the source information file\n"
b9179170
MV
64 );
65
66 return true;
67}
68
69int main(int argc, const char *argv[]) /*{{{*/
70{
59e81cec
MV
71 CommandLine::Dispatch Cmds[] = {
72 // query
ec4371ac 73 {"list",&DoList},
631800b1 74 {"search", &DoSearch},
501cd23e 75 {"show", &ShowPackage},
59e81cec 76
6d73fe5b 77 // package stuff
b9179170
MV
78 {"install",&DoInstall},
79 {"remove", &DoInstall},
825220b5
JAK
80 {"autoremove", &DoInstall},
81 {"auto-remove", &DoInstall},
8a59cc32 82 {"purge", &DoInstall},
59e81cec 83
6d73fe5b 84 // system wide stuff
b9179170 85 {"update",&DoUpdate},
59e81cec
MV
86 {"upgrade",&DoUpgrade},
87 {"full-upgrade",&DoDistUpgrade},
88 // for compat with muscle memory
89 {"dist-upgrade",&DoDistUpgrade},
90
cfacba52
MV
91 // misc
92 {"edit-sources",&EditSources},
59e81cec 93
b9179170
MV
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
3163087b
MV
101 // Init the signals
102 InitSignals();
103
104 // Init the output
b9179170
MV
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
b9179170 117 // Parse the command line and initialize the package library
ad7e0941
DK
118 CommandLine CmdL;
119 ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
b9179170 120
ad7e0941 121 if(!isatty(STDOUT_FILENO) &&
14109555
MV
122 _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
123 {
124 std::cerr << std::endl
125 << "WARNING: " << argv[0] << " "
126 << "does not have a stable CLI interface yet. "
127 << "Use with caution in scripts."
128 << std::endl
129 << std::endl;
130 }
14109555 131
b9179170
MV
132 // see if we are in simulate mode
133 CheckSimulateMode(CmdL);
134
135 // parse args
136 CmdL.DispatchArg(Cmds);
137
138 // Print any errors or warnings found during parsing
139 bool const Errors = _error->PendingError();
140 if (_config->FindI("quiet",0) > 0)
141 _error->DumpErrors();
142 else
143 _error->DumpErrors(GlobalError::DEBUG);
144 return Errors == true ? 100 : 0;
145}
146 /*}}}*/