]>
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 for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
43 COMMON_ARCH
,__DATE__
,__TIME__
);
45 // FIXME: generate from CommandLine
47 _("Usage: apt [options] command\n"
51 " list - list packages based on package names\n"
52 " search - search in package descriptions\n"
53 " show - show package details\n"
55 " update - update list of available packages\n"
57 " install - install packages\n"
58 " remove - remove packages\n"
60 " upgrade - upgrade the system by installing/upgrading packages\n"
61 " full-upgrade - upgrade the system by removing/installing/upgrading packages\n"
63 " edit-sources - edit the source information file\n"
69 int main(int argc
, const char *argv
[]) /*{{{*/
71 CommandLine::Dispatch Cmds
[] = {
74 {"search", &FullTextSearch
},
75 {"show", &APT::Cmd::ShowPackage
},
78 {"install",&DoInstall
},
79 {"remove", &DoInstall
},
80 {"purge", &DoInstall
},
84 {"upgrade",&DoUpgrade
},
85 {"full-upgrade",&DoDistUpgrade
},
86 // for compat with muscle memory
87 {"dist-upgrade",&DoDistUpgrade
},
90 {"edit-sources",&EditSources
},
97 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt", CommandLine::GetCommand(Cmds
, argc
, argv
));
105 // Set up gettext support
106 setlocale(LC_ALL
,"");
109 if(pkgInitConfig(*_config
) == false)
111 _error
->DumpErrors();
115 // some different defaults
116 _config
->CndSet("DPkg::Progress-Fancy", "1");
117 _config
->CndSet("Apt::Color", "1");
118 _config
->CndSet("APT::Get::Upgrade-Allow-New", true);
119 _config
->CndSet("APT::Cmd::Show-Update-Stats", true);
121 // Parse the command line and initialize the package library
123 ParseCommandLine(CmdL
, Cmds
, Args
.data(), NULL
, &_system
, argc
, argv
, ShowHelp
);
125 if(!isatty(STDOUT_FILENO
) &&
126 _config
->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
128 std::cerr
<< std::endl
129 << "WARNING: " << argv
[0] << " "
130 << "does not have a stable CLI interface yet. "
131 << "Use with caution in scripts."
136 // see if we are in simulate mode
137 CheckSimulateMode(CmdL
);
140 CmdL
.DispatchArg(Cmds
);
142 // Print any errors or warnings found during parsing
143 bool const Errors
= _error
->PendingError();
144 if (_config
->FindI("quiet",0) > 0)
145 _error
->DumpErrors();
147 _error
->DumpErrors(GlobalError::DEBUG
);
148 return Errors
== true ? 100 : 0;