summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/cmndline.cc2
-rw-r--r--apt-pkg/contrib/cmndline.h2
-rw-r--r--apt-private/private-cmndline.cc69
-rw-r--r--apt-private/private-cmndline.h3
-rw-r--r--apt-private/private-main.cc32
-rw-r--r--apt-private/private-main.h4
-rw-r--r--cmdline/apt-cache.cc22
-rw-r--r--cmdline/apt-cdrom.cc20
-rw-r--r--cmdline/apt-config.cc24
-rw-r--r--cmdline/apt-extracttemplates.cc26
-rw-r--r--cmdline/apt-get.cc27
-rw-r--r--cmdline/apt-helper.cc23
-rw-r--r--cmdline/apt-internal-solver.cc25
-rw-r--r--cmdline/apt-mark.cc22
-rw-r--r--cmdline/apt-sortpkgs.cc27
-rw-r--r--cmdline/apt.cc47
-rw-r--r--ftparchive/apt-ftparchive.cc36
17 files changed, 159 insertions, 252 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index 60ce90f1f..d299bbbdf 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -411,7 +411,7 @@ unsigned int CommandLine::FileSize() const
}
/*}}}*/
// CommandLine::DispatchArg - Do something with the first arg /*{{{*/
-bool CommandLine::DispatchArg(DispatchWithHelp *Map,bool NoMatch)
+bool CommandLine::DispatchArg(DispatchWithHelp const * const Map,bool NoMatch)
{
int I;
for (I = 0; Map[I].Match != 0; I++)
diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h
index a698a18b8..33d9f9f3a 100644
--- a/apt-pkg/contrib/cmndline.h
+++ b/apt-pkg/contrib/cmndline.h
@@ -85,7 +85,7 @@ class CommandLine
void ShowHelp();
unsigned int FileSize() const APT_PURE;
bool DispatchArg(Dispatch *List,bool NoMatch = true);
- bool DispatchArg(DispatchWithHelp *List,bool NoMatch = true);
+ bool DispatchArg(DispatchWithHelp const * const List,bool NoMatch = true);
static char const * GetCommand(Dispatch const * const Map,
unsigned int const argc, char const * const * const argv) APT_PURE;
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc
index 265c5d482..a0acbbd79 100644
--- a/apt-private/private-cmndline.cc
+++ b/apt-private/private-cmndline.cc
@@ -127,6 +127,32 @@ static bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char con
return true;
}
/*}}}*/
+static bool addArgumentsAPTExtractTemplates(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/
+{
+ addArg('t',"tempdir","APT::ExtractTemplates::TempDir",CommandLine::HasArg);
+ return true;
+}
+ /*}}}*/
+static bool addArgumentsAPTFTPArchive(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/
+{
+ addArg(0,"md5","APT::FTPArchive::MD5",0);
+ addArg(0,"sha1","APT::FTPArchive::SHA1",0);
+ addArg(0,"sha256","APT::FTPArchive::SHA256",0);
+ addArg(0,"sha512","APT::FTPArchive::SHA512",0);
+ addArg('d',"db","APT::FTPArchive::DB",CommandLine::HasArg);
+ addArg('s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg);
+ addArg(0,"delink","APT::FTPArchive::DeLinkAct",0);
+ addArg(0,"readonly","APT::FTPArchive::ReadOnlyDB",0);
+ addArg(0,"contents","APT::FTPArchive::Contents",0);
+ addArg('a',"arch","APT::FTPArchive::Architecture",CommandLine::HasArg);
+ return true;
+}
+ /*}}}*/
+static bool addArgumentsAPTInternalSolver(std::vector<CommandLine::Args> &, char const * const)/*{{{*/
+{
+ return true;
+}
+ /*}}}*/
static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
{
if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
@@ -257,6 +283,12 @@ static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const
return true;
}
/*}}}*/
+static bool addArgumentsAPTSortPkgs(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/
+{
+ addArg('s',"source","APT::SortPkgs::Source",0);
+ return true;
+}
+ /*}}}*/
static bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
{
if (CmdMatches("list"))
@@ -299,8 +331,16 @@ std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char c
addArgumentsAPTCDROM(Args, Cmd);
else if (strcmp(Program, "apt-config") == 0)
addArgumentsAPTConfig(Args, Cmd);
+ else if (strcmp(Program, "apt-extracttemplates") == 0)
+ addArgumentsAPTExtractTemplates(Args, Cmd);
+ else if (strcmp(Program, "apt-ftparchive") == 0)
+ addArgumentsAPTFTPArchive(Args, Cmd);
+ else if (strcmp(Program, "apt-internal-solver") == 0)
+ addArgumentsAPTInternalSolver(Args, Cmd);
else if (strcmp(Program, "apt-mark") == 0)
addArgumentsAPTMark(Args, Cmd);
+ else if (strcmp(Program, "apt-sortpkg") == 0)
+ addArgumentsAPTSortPkgs(Args, Cmd);
else if (strcmp(Program, "apt") == 0)
addArgumentsAPT(Args, Cmd);
@@ -340,10 +380,19 @@ static void BinarySpecificConfiguration(char const * const Binary) /*{{{*/
_config->MoveSubTree(conf.c_str(), NULL);
}
/*}}}*/
-void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, CommandLine::Args * const Args,/*{{{*/
+void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, char const * const Binary,/*{{{*/
Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[], bool(*ShowHelp)(CommandLine &, CommandLine::DispatchWithHelp const *))
{
- CmdL = CommandLine(Args,_config);
+ // Args running out of scope invalidates the pointer stored in CmdL,
+ // but we don't use the pointer after this function, so we ignore
+ // this problem for now and figure something out if we have to.
+ std::vector<CommandLine::Args> Args;
+ if (Cmds != nullptr && Cmds[0].Handler != nullptr)
+ Args = getCommandArgs(Binary, CommandLine::GetCommand(Cmds, argc, argv));
+ else
+ Args = getCommandArgs(Binary, Binary);
+ CmdL = CommandLine(Args.data(), _config);
+
if (Cnf != NULL && pkgInitConfig(**Cnf) == false)
{
_error->DumpErrors();
@@ -377,3 +426,19 @@ void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * C
}
}
/*}}}*/
+unsigned short DispatchCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * const Cmds) /*{{{*/
+{
+ // Match the operation
+ bool const returned = (Cmds != nullptr) ? CmdL.DispatchArg(Cmds) : true;
+
+ // Print any errors or warnings found during parsing
+ bool const Errors = _error->PendingError();
+ if (_config->FindI("quiet",0) > 0)
+ _error->DumpErrors();
+ else
+ _error->DumpErrors(GlobalError::DEBUG);
+ if (returned == false)
+ return 100;
+ return Errors == true ? 100 : 0;
+}
+ /*}}}*/
diff --git a/apt-private/private-cmndline.h b/apt-private/private-cmndline.h
index 0d6c0bba6..5674088bc 100644
--- a/apt-private/private-cmndline.h
+++ b/apt-private/private-cmndline.h
@@ -10,8 +10,9 @@ class Configuration;
class pkgSystem;
APT_PUBLIC std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char const * const Cmd);
-APT_PUBLIC void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, CommandLine::Args * const Args,
+APT_PUBLIC void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, char const * const Binary,
Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[],
bool(*ShowHelp)(CommandLine &, CommandLine::DispatchWithHelp const *));
+APT_PUBLIC unsigned short DispatchCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * const Cmds);
#endif
diff --git a/apt-private/private-main.cc b/apt-private/private-main.cc
index 3886c7df6..9eb306834 100644
--- a/apt-private/private-main.cc
+++ b/apt-private/private-main.cc
@@ -2,6 +2,7 @@
#include <apt-pkg/cmndline.h>
#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
#include <apt-private/private-main.h>
@@ -13,14 +14,18 @@
#include <apti18n.h>
-void InitSignals()
+void InitLocale() /*{{{*/
+{
+ setlocale(LC_ALL,"");
+ textdomain(PACKAGE);
+}
+ /*}}}*/
+void InitSignals() /*{{{*/
{
- // Setup the signals
signal(SIGPIPE,SIG_IGN);
}
-
-
-void CheckSimulateMode(CommandLine &CmdL)
+ /*}}}*/
+void CheckIfSimulateMode(CommandLine &CmdL) /*{{{*/
{
// disable locking in simulation, but show the message only for users
// as root hasn't the same problems like unreadable files which can heavily
@@ -39,3 +44,20 @@ void CheckSimulateMode(CommandLine &CmdL)
_config->Set("Debug::NoLocking",true);
}
}
+ /*}}}*/
+void CheckIfCalledByScript(int argc, const char *argv[]) /*{{{*/
+{
+ if (unlikely(argc < 1)) return;
+
+ if(!isatty(STDOUT_FILENO) &&
+ _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
+ {
+ std::cerr << std::endl
+ << "WARNING: " << flNotDir(argv[0]) << " "
+ << "does not have a stable CLI interface. "
+ << "Use with caution in scripts."
+ << std::endl
+ << std::endl;
+ }
+}
+ /*}}}*/
diff --git a/apt-private/private-main.h b/apt-private/private-main.h
index a03bf4441..db6d3e0b7 100644
--- a/apt-private/private-main.h
+++ b/apt-private/private-main.h
@@ -5,7 +5,9 @@
class CommandLine;
-APT_PUBLIC void CheckSimulateMode(CommandLine &CmdL);
+APT_PUBLIC void InitLocale();
APT_PUBLIC void InitSignals();
+APT_PUBLIC void CheckIfSimulateMode(CommandLine &CmdL);
+APT_PUBLIC void CheckIfCalledByScript(int argc, const char *argv[]);
#endif
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index 4b3a74922..67e4a8523 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -45,6 +45,7 @@
#include <apt-private/private-cmndline.h>
#include <apt-private/private-show.h>
#include <apt-private/private-search.h>
+#include <apt-private/private-main.h>
#include <regex.h>
#include <stddef.h>
@@ -1559,6 +1560,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
{"gencaches",&GenCaches, nullptr},
{"showsrc",&ShowSrcPackage, _("Show source records")},
@@ -1580,30 +1583,15 @@ int main(int argc,const char *argv[]) /*{{{*/
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs("apt-cache", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
// Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-cache", &_config, &_system, argc, argv, ShowHelp);
InitOutput();
if (_config->Exists("APT::Cache::Generate") == true)
_config->Set("pkgCacheFile::Generate", _config->FindB("APT::Cache::Generate", true));
- // Match the operation
- CmdL.DispatchArg(Cmds);
-
- // Print any errors or warnings found during parsing
- bool const Errors = _error->PendingError();
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors();
- else
- _error->DumpErrors(GlobalError::DEBUG);
- return Errors == true ? 100 : 0;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc
index 1838a76fe..3fc3faf4a 100644
--- a/cmdline/apt-cdrom.cc
+++ b/cmdline/apt-cdrom.cc
@@ -32,6 +32,7 @@
#include <apt-private/private-cmndline.h>
#include <apt-private/private-output.h>
+#include <apt-private/private-main.h>
#include <apti18n.h>
/*}}}*/
@@ -242,31 +243,20 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
{"add", &DoAdd, "Add a CDROM"},
{"ident", &DoIdent, "Report the identity of a CDROM"},
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs("apt-cdrom", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
// Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-cdrom", &_config, &_system, argc, argv, ShowHelp);
InitOutput();
- // Match the operation
- bool returned = CmdL.DispatchArg(Cmds);
-
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors();
- else
- _error->DumpErrors(GlobalError::DEBUG);
- return returned == true ? 0 : 100;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc
index e0383e019..3ccfa9a95 100644
--- a/cmdline/apt-config.cc
+++ b/cmdline/apt-config.cc
@@ -32,6 +32,7 @@
#include <string.h>
#include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
#include <apti18n.h>
/*}}}*/
@@ -107,21 +108,17 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
{"shell", &DoShell, _("get configuration values via shell evaluation")},
{"dump", &DoDump, _("show the active configuration setting")},
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs("apt-config", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
// Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-config", &_config, &_system, argc, argv, ShowHelp);
std::vector<std::string> const langs = APT::Configuration::getLanguages(true);
_config->Clear("Acquire::Languages");
@@ -154,17 +151,6 @@ int main(int argc,const char *argv[]) /*{{{*/
for (std::vector<std::string>::const_iterator p = profiles.begin(); p != profiles.end(); ++p)
_config->Set("APT::Build-Profiles::", *p);
- // Match the operation
- CmdL.DispatchArg(Cmds);
-
- // Print any errors or warnings found during parsing
- if (_error->empty() == false)
- {
- bool Errors = _error->PendingError();
- _error->DumpErrors();
- return Errors == true?100:0;
- }
-
- return 0;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index cd52cfe33..e28b42870 100644
--- a/cmdline/apt-extracttemplates.cc
+++ b/cmdline/apt-extracttemplates.cc
@@ -34,6 +34,7 @@
#include <apt-pkg/mmap.h>
#include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
#include <iostream>
#include <stdio.h>
@@ -344,34 +345,15 @@ static bool Go(CommandLine &CmdL)
/*}}}*/
int main(int argc, const char **argv) /*{{{*/
{
- CommandLine::Args Args[] = {
- {'h',"help","help",0},
- {'v',"version","version",0},
- {'t',"tempdir","APT::ExtractTemplates::TempDir",CommandLine::HasArg},
- {'c',"config-file",0,CommandLine::ConfigFile},
- {'o',"option",0,CommandLine::ArbItem},
- {0,0,0,0}};
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
+ InitLocale();
// Parse the command line and initialize the package library
CommandLine::DispatchWithHelp Cmds[] = {{nullptr, nullptr, nullptr}};
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-extracttemplates", &_config, &_system, argc, argv, ShowHelp);
Go(CmdL);
- // Print any errors or warnings found during operation
- if (_error->empty() == false)
- {
- // This goes to stderr..
- bool Errors = _error->PendingError();
- _error->DumpErrors();
- return Errors == true?100:0;
- }
-
- return 0;
+ return DispatchCommandLine(CmdL, nullptr);
}
/*}}}*/
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index be5bc0851..1379c607e 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -1622,6 +1622,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
{"update", &DoUpdate, _("Retrieve new lists of packages")},
{"upgrade", &DoUpgrade, _("Perform an upgrade")},
@@ -1648,34 +1650,15 @@ int main(int argc,const char *argv[]) /*{{{*/
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
// Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-get", &_config, &_system, argc, argv, ShowHelp);
- // see if we are in simulate mode
- CheckSimulateMode(CmdL);
-
- // Init the signals
InitSignals();
-
- // Setup the output streams
InitOutput();
- // Match the operation
- CmdL.DispatchArg(Cmds);
+ CheckIfSimulateMode(CmdL);
- // Print any errors or warnings found during parsing
- bool const Errors = _error->PendingError();
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors();
- else
- _error->DumpErrors(GlobalError::DEBUG);
- return Errors == true ? 100 : 0;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index 3df858813..ff9061dc7 100644
--- a/cmdline/apt-helper.cc
+++ b/cmdline/apt-helper.cc
@@ -22,6 +22,7 @@
#include <apt-private/private-output.h>
#include <apt-private/private-download.h>
#include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
#include <apt-pkg/srvrec.h>
#include <iostream>
@@ -136,6 +137,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
int main(int argc,const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
{"download-file", &DoDownloadFile, _("download the given uri to the target-path")},
{"srv-lookup", &DoSrvLookup, _("lookup a SRV record (e.g. _http._tcp.ftp.debian.org)")},
@@ -143,28 +146,12 @@ int main(int argc,const char *argv[]) /*{{{*/
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs(
- "apt-helper", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
// Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-helper", &_config, &_system, argc, argv, ShowHelp);
InitOutput();
- // Match the operation
- CmdL.DispatchArg(Cmds);
-
- // Print any errors or warnings found during parsing
- bool const Errors = _error->PendingError();
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors();
- else
- _error->DumpErrors(GlobalError::DEBUG);
- return Errors == true ? 100 : 0;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc
index fbcbf07e9..278f6d471 100644
--- a/cmdline/apt-internal-solver.cc
+++ b/cmdline/apt-internal-solver.cc
@@ -27,6 +27,7 @@
#include <apt-private/private-output.h>
#include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
#include <string.h>
#include <iostream>
@@ -68,20 +69,13 @@ APT_NORETURN static void DIE(std::string const &message) { /*{{{*/
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
- CommandLine::Args Args[] = {
- {'h',"help","help",0},
- {'v',"version","version",0},
- {'q',"quiet","quiet",CommandLine::IntLevel},
- {'q',"silent","quiet",CommandLine::IntLevel},
- {'c',"config-file",0,CommandLine::ConfigFile},
- {'o',"option",0,CommandLine::ArbItem},
- {0,0,0,0}};
-
- // we really don't need anything
- DropPrivileges();
+ InitLocale();
+
+ // we really don't need anything
+ DropPrivileges();
CommandLine CmdL;
- ParseCommandLine(CmdL, nullptr, Args, &_config, NULL, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, nullptr, "apt-internal-solver", &_config, NULL, argc, argv, ShowHelp);
if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0)
{
@@ -188,11 +182,6 @@ int main(int argc,const char *argv[]) /*{{{*/
EDSP::WriteProgress(100, "Done", output);
- bool const Errors = _error->PendingError();
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors(std::cerr);
- else
- _error->DumpErrors(std::cerr, GlobalError::DEBUG);
- return Errors == true ? 100 : 0;
+ return DispatchCommandLine(CmdL, nullptr);
}
/*}}}*/
diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc
index 361d4e553..0a5bb164a 100644
--- a/cmdline/apt-mark.cc
+++ b/cmdline/apt-mark.cc
@@ -24,6 +24,7 @@
#include <apt-private/private-cmndline.h>
#include <apt-private/private-output.h>
+#include <apt-private/private-main.h>
#include <errno.h>
#include <fcntl.h>
@@ -315,6 +316,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
{"auto",&DoAuto, _("Mark the given packages as automatically installed")},
{"manual",&DoAuto, _("Mark the given packages as manually installed")},
@@ -337,26 +340,11 @@ int main(int argc,const char *argv[]) /*{{{*/
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs("apt-mark", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-mark", &_config, &_system, argc, argv, ShowHelp);
InitOutput();
- // Match the operation
- CmdL.DispatchArg(Cmds);
-
- // Print any errors or warnings found during parsing
- bool const Errors = _error->PendingError();
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors();
- else
- _error->DumpErrors(GlobalError::DEBUG);
- return Errors == true ? 100 : 0;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc
index e3d520a96..93aa5a76b 100644
--- a/cmdline/apt-sortpkgs.cc
+++ b/cmdline/apt-sortpkgs.cc
@@ -24,6 +24,7 @@
#include <apt-pkg/pkgsystem.h>
#include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
#include <vector>
#include <algorithm>
@@ -157,36 +158,18 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
{
- CommandLine::Args Args[] = {
- {'h',"help","help",0},
- {'v',"version","version",0},
- {'s',"source","APT::SortPkgs::Source",0},
- {'c',"config-file",0,CommandLine::ConfigFile},
- {'o',"option",0,CommandLine::ArbItem},
- {0,0,0,0}};
-
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
+ InitLocale();
// Parse the command line and initialize the package library
CommandLine::DispatchWithHelp Cmds[] = {{nullptr, nullptr, nullptr}};
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
+ ParseCommandLine(CmdL, Cmds, "apt-sortpkgs", &_config, &_system, argc, argv, ShowHelp);
// Match the operation
for (unsigned int I = 0; I != CmdL.FileSize(); I++)
if (DoIt(CmdL.FileList[I]) == false)
break;
-
- // Print any errors or warnings found during parsing
- if (_error->empty() == false)
- {
- bool Errors = _error->PendingError();
- _error->DumpErrors();
- return Errors == true?100:0;
- }
-
- return 0;
+
+ return DispatchCommandLine(CmdL, nullptr);
}
/*}}}*/
diff --git a/cmdline/apt.cc b/cmdline/apt.cc
index 53735356d..98e715625 100644
--- a/cmdline/apt.cc
+++ b/cmdline/apt.cc
@@ -60,6 +60,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
int main(int argc, const char *argv[]) /*{{{*/
{
+ InitLocale();
+
CommandLine::DispatchWithHelp Cmds[] = {
// query
{"list", &DoList, _("list packages based on package names")},
@@ -85,51 +87,16 @@ int main(int argc, const char *argv[]) /*{{{*/
{nullptr, nullptr, nullptr}
};
- std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
-
- // Init the signals
+ // FIXME: Those ignore commandline configuration like -q
InitSignals();
-
- // Init the output
InitOutput();
- // Set up gettext support
- setlocale(LC_ALL,"");
- textdomain(PACKAGE);
-
- if(pkgInitConfig(*_config) == false)
- {
- _error->DumpErrors();
- return 100;
- }
-
- // Parse the command line and initialize the package library
CommandLine CmdL;
- ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
-
- if(!isatty(STDOUT_FILENO) &&
- _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
- {
- std::cerr << std::endl
- << "WARNING: " << argv[0] << " "
- << "does not have a stable CLI interface yet. "
- << "Use with caution in scripts."
- << std::endl
- << std::endl;
- }
-
- // see if we are in simulate mode
- CheckSimulateMode(CmdL);
+ ParseCommandLine(CmdL, Cmds, "apt", &_config, &_system, argc, argv, ShowHelp);
- // parse args
- CmdL.DispatchArg(Cmds);
+ CheckIfCalledByScript(argc, argv);
+ CheckIfSimulateMode(CmdL);
- // Print any errors or warnings found during parsing
- bool const Errors = _error->PendingError();
- if (_config->FindI("quiet",0) > 0)
- _error->DumpErrors();
- else
- _error->DumpErrors(GlobalError::DEBUG);
- return Errors == true ? 100 : 0;
+ return DispatchCommandLine(CmdL, Cmds);
}
/*}}}*/
diff --git a/ftparchive/apt-ftparchive.cc b/ftparchive/apt-ftparchive.cc
index 857f0aff5..ca03080ca 100644
--- a/ftparchive/apt-ftparchive.cc
+++ b/ftparchive/apt-ftparchive.cc
@@ -21,6 +21,7 @@
#include <apt-private/private-cmndline.h>
#include <apt-private/private-output.h>
+#include <apt-private/private-main.h>
#include <algorithm>
#include <climits>
@@ -1026,25 +1027,7 @@ static bool Clean(CommandLine &CmdL)
int main(int argc, const char *argv[])
{
- setlocale(LC_ALL, "");
- CommandLine::Args Args[] = {
- {'h',"help","help",0},
- {0,"md5","APT::FTPArchive::MD5",0},
- {0,"sha1","APT::FTPArchive::SHA1",0},
- {0,"sha256","APT::FTPArchive::SHA256",0},
- {0,"sha512","APT::FTPArchive::SHA512",0},
- {'v',"version","version",0},
- {'d',"db","APT::FTPArchive::DB",CommandLine::HasArg},
- {'s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg},
- {'q',"quiet","quiet",CommandLine::IntLevel},
- {'q',"silent","quiet",CommandLine::IntLevel},
- {0,"delink","APT::FTPArchive::DeLinkAct",0},
- {0,"readonly","APT::FTPArchive::ReadOnlyDB",0},
- {0,"contents","APT::FTPArchive::Contents",0},
- {'a',"arch","APT::FTPArchive::Architecture",CommandLine::HasArg},
- {'c',"config-file",0,CommandLine::ConfigFile},
- {'o',"option",0,CommandLine::ArbItem},
- {0,0,0,0}};
+ InitLocale();
CommandLine::DispatchWithHelp Cmds[] = {
{"packages",&SimpleGenPackages, nullptr},
@@ -1057,21 +1040,12 @@ int main(int argc, const char *argv[])
};
// Parse the command line and initialize the package library
- CommandLine CmdL(Args,_config);
- ParseCommandLine(CmdL, Cmds, Args, &_config, NULL, argc, argv, ShowHelp);
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, "apt-ftparchive", &_config, NULL, argc, argv, ShowHelp);
_config->CndSet("quiet",0);
Quiet = _config->FindI("quiet",0);
InitOutput(clog.rdbuf());
- // Match the operation
- CmdL.DispatchArg(Cmds);
-
- if (_error->empty() == false)
- {
- bool Errors = _error->PendingError();
- _error->DumpErrors();
- return Errors == true?100:0;
- }
- return 0;
+ return DispatchCommandLine(CmdL, Cmds);
}