summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-10-24 22:43:37 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-11-04 18:04:03 +0100
commite7e10e47476606e3b2274cf66b1e8ea74b236757 (patch)
tree3daed3cc14405879034c562993a7b5399992f2e3 /cmdline
parentcbbee23e7768750ca1c8b49bdfbf8a650131bbb6 (diff)
deduplicate main methods
All mains pretty much do the same thing, so lets try a little harder to move the common parts into -private to have the real differences more visible. Git-Dch: Ignore
Diffstat (limited to 'cmdline')
-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
10 files changed, 53 insertions, 210 deletions
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);
}
/*}}}*/