1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
7 Returns 100 on failure, 0 on success.
9 ##################################################################### */
11 // Include Files /*{{{*/
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>
44 #include <apt-pkg/hashes.h>
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>
58 #include <apt-private/private-utils.h>
59 #include <apt-private/private-sources.h>
64 bool ShowHelp(CommandLine
&CmdL
)
66 ioprintf(c1out
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
67 COMMON_ARCH
,__DATE__
,__TIME__
);
69 // FIXME: generate from CommandLine
71 _("Usage: apt [options] command\n"
75 " list - list packages based on package names\n"
76 " search - search in package descriptions\n"
77 " show - show package details\n"
79 " update - update list of available packages\n"
80 " install - install packages\n"
81 " upgrade - upgrade the systems packages\n"
83 " edit-sources - edit the source information file\n"
89 int main(int argc
, const char *argv
[]) /*{{{*/
91 CommandLine::Dispatch Cmds
[] = {{"list",&List
},
92 {"search", &FullTextSearch
},
93 {"show", &APT::Cmd::ShowPackage
},
95 {"install",&DoInstall
},
96 {"remove", &DoInstall
},
98 {"upgrade",&DoUpgradeWithAllowNewPackages
},
100 {"edit-sources",&EditSources
},
106 std::vector
<CommandLine::Args
> Args
= getCommandArgs("apt", CommandLine::GetCommand(Cmds
, argc
, argv
));
110 std::cerr
<< std::endl
111 << "WARNING WARNING "
113 << " is *NOT* intended for scripts "
114 << "use at your own peril^Wrisk"
121 // Set up gettext support
122 setlocale(LC_ALL
,"");
125 if(pkgInitConfig(*_config
) == false)
127 _error
->DumpErrors();
131 // FIXME: move into a new libprivate/private-install.cc:Install()
132 _config
->Set("DPkgPM::Progress", "1");
133 _config
->Set("Apt::Color", "1");
135 // Parse the command line and initialize the package library
136 CommandLine
CmdL(Args
.data(), _config
);
137 if (CmdL
.Parse(argc
, argv
) == false ||
138 pkgInitSystem(*_config
, _system
) == false)
140 _error
->DumpErrors();
144 // See if the help should be shown
145 if (_config
->FindB("help") == true ||
146 _config
->FindB("version") == true ||
147 CmdL
.FileSize() == 0)
153 // see if we are in simulate mode
154 CheckSimulateMode(CmdL
);
157 CmdL
.DispatchArg(Cmds
);
159 // Print any errors or warnings found during parsing
160 bool const Errors
= _error
->PendingError();
161 if (_config
->FindI("quiet",0) > 0)
162 _error
->DumpErrors();
164 _error
->DumpErrors(GlobalError::DEBUG
);
165 return Errors
== true ? 100 : 0;