]>
git.saurik.com Git - apt.git/blob - cmdline/apt.cc
1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
7 Returns 100 on failure, 0 on success.
9 ##################################################################### */
11 // Include Files /*{{{*/
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>
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>
40 static bool ShowHelp(CommandLine
&)
42 ioprintf(c1out
, "%s %s (%s)\n", PACKAGE
, PACKAGE_VERSION
, COMMON_ARCH
);
44 // FIXME: generate from CommandLine
46 _("Usage: apt [options] command\n"
50 " list - list packages based on package names\n"
51 " search - search in package descriptions\n"
52 " show - show package details\n"
54 " update - update list of available packages\n"
56 " install - install packages\n"
57 " remove - remove packages\n"
59 " upgrade - upgrade the system by installing/upgrading packages\n"
60 " full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
62 " edit-sources - edit the source information file\n"
68 int main(int argc
, const char *argv
[]) /*{{{*/
70 CommandLine::Dispatch Cmds
[] = {
73 {"search", &FullTextSearch
},
74 {"show", &APT::Cmd::ShowPackage
},
77 {"install",&DoInstall
},
78 {"remove", &DoInstall
},
79 {"purge", &DoInstall
},
83 {"upgrade",&DoUpgrade
},
84 {"full-upgrade",&DoDistUpgrade
},
85 // for compat with muscle memory
86 {"dist-upgrade",&DoDistUpgrade
},
89 {"edit-sources",&EditSources
},
96 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt", CommandLine::GetCommand(Cmds
, argc
, argv
));
104 // Set up gettext support
105 setlocale(LC_ALL
,"");
108 if(pkgInitConfig(*_config
) == false)
110 _error
->DumpErrors();
114 // some different defaults
115 _config
->CndSet("DPkg::Progress-Fancy", "1");
116 _config
->CndSet("Apt::Color", "1");
117 _config
->CndSet("APT::Get::Upgrade-Allow-New", true);
118 _config
->CndSet("APT::Cmd::Show-Update-Stats", true);
120 // Parse the command line and initialize the package library
122 ParseCommandLine(CmdL
, Cmds
, Args
.data(), NULL
, &_system
, argc
, argv
, ShowHelp
);
124 if(!isatty(STDOUT_FILENO
) &&
125 _config
->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
127 std::cerr
<< std::endl
128 << "WARNING: " << argv
[0] << " "
129 << "does not have a stable CLI interface yet. "
130 << "Use with caution in scripts."
135 // see if we are in simulate mode
136 CheckSimulateMode(CmdL
);
139 CmdL
.DispatchArg(Cmds
);
141 // Print any errors or warnings found during parsing
142 bool const Errors
= _error
->PendingError();
143 if (_config
->FindI("quiet",0) > 0)
144 _error
->DumpErrors();
146 _error
->DumpErrors(GlobalError::DEBUG
);
147 return Errors
== true ? 100 : 0;