]>
git.saurik.com Git - apt.git/blob - cmdline/apt.cc
53735356dcd6d42d4275f33e2add9a51090fc6ca
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
&, CommandLine::DispatchWithHelp
const * Cmds
)
42 ioprintf(c1out
, "%s %s (%s)\n", PACKAGE
, PACKAGE_VERSION
, COMMON_ARCH
);
44 // FIXME: generate from CommandLine
46 _("Usage: apt [options] command\n"
50 << _("Commands:") << std::endl
;
51 for (; Cmds
->Handler
!= nullptr; ++Cmds
)
53 if (Cmds
->Help
== nullptr)
55 std::cout
<< " " << Cmds
->Match
<< " - " << Cmds
->Help
<< std::endl
;
61 int main(int argc
, const char *argv
[]) /*{{{*/
63 CommandLine::DispatchWithHelp Cmds
[] = {
65 {"list", &DoList
, _("list packages based on package names")},
66 {"search", &DoSearch
, _("search in package descriptions")},
67 {"show", &ShowPackage
, _("show package details")},
70 {"install", &DoInstall
, _("install packages")},
71 {"remove", &DoInstall
, _("remove packages")},
72 {"autoremove", &DoInstall
, _("Remove automatically all unused packages")},
73 {"auto-remove", &DoInstall
, nullptr},
74 {"purge", &DoInstall
, nullptr},
77 {"update", &DoUpdate
, _("update list of available packages")},
78 {"upgrade", &DoUpgrade
, _("upgrade the system by installing/upgrading packages")},
79 {"full-upgrade", &DoDistUpgrade
, _("upgrade the system by removing/installing/upgrading packages")},
80 {"dist-upgrade", &DoDistUpgrade
, nullptr}, // for compat with muscle memory
83 {"edit-sources", &EditSources
, _("edit the source information file")},
84 {"moo", &DoMoo
, nullptr},
85 {nullptr, nullptr, nullptr}
88 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt", CommandLine::GetCommand(Cmds
, argc
, argv
));
96 // Set up gettext support
100 if(pkgInitConfig(*_config
) == false)
102 _error
->DumpErrors();
106 // Parse the command line and initialize the package library
108 ParseCommandLine(CmdL
, Cmds
, Args
.data(), NULL
, &_system
, argc
, argv
, ShowHelp
);
110 if(!isatty(STDOUT_FILENO
) &&
111 _config
->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
113 std::cerr
<< std::endl
114 << "WARNING: " << argv
[0] << " "
115 << "does not have a stable CLI interface yet. "
116 << "Use with caution in scripts."
121 // see if we are in simulate mode
122 CheckSimulateMode(CmdL
);
125 CmdL
.DispatchArg(Cmds
);
127 // Print any errors or warnings found during parsing
128 bool const Errors
= _error
->PendingError();
129 if (_config
->FindI("quiet",0) > 0)
130 _error
->DumpErrors();
132 _error
->DumpErrors(GlobalError::DEBUG
);
133 return Errors
== true ? 100 : 0;