summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-cache.cc18
-rw-r--r--cmdline/apt-cdrom.cc15
-rw-r--r--cmdline/apt-config.cc15
-rw-r--r--cmdline/apt-extracttemplates.cc32
-rw-r--r--cmdline/apt-get.cc22
-rw-r--r--cmdline/apt-helper.cc21
-rw-r--r--cmdline/apt-internal-solver.cc17
-rw-r--r--cmdline/apt-mark.cc22
-rw-r--r--cmdline/apt-sortpkgs.cc24
-rw-r--r--cmdline/apt.cc20
-rw-r--r--cmdline/makefile8
11 files changed, 43 insertions, 171 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc
index 9bac45029..12ed4f719 100644
--- a/cmdline/apt-cache.cc
+++ b/cmdline/apt-cache.cc
@@ -1896,23 +1896,9 @@ int main(int argc,const char *argv[]) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(),_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- _error->DumpErrors();
- return 100;
- }
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- CmdL.FileSize() == 0)
- {
- ShowHelp(CmdL);
- return 0;
- }
-
// Deal with stdout not being a tty
if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
_config->Set("quiet","1");
diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc
index 53efe65b8..8ac73fd7e 100644
--- a/cmdline/apt-cdrom.cc
+++ b/cmdline/apt-cdrom.cc
@@ -249,19 +249,8 @@ int main(int argc,const char *argv[]) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(),_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true || _config->FindB("version") == true ||
- CmdL.FileSize() == 0)
- return ShowHelp(CmdL);
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
// Deal with stdout not being a tty
if (isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc
index 40ba468eb..e0b8a624e 100644
--- a/cmdline/apt-config.cc
+++ b/cmdline/apt-config.cc
@@ -115,19 +115,8 @@ int main(int argc,const char *argv[]) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(),_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- CmdL.FileSize() == 0)
- return ShowHelp(CmdL);
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
std::vector<std::string> const langs = APT::Configuration::getLanguages(true);
_config->Clear("Acquire::Languages");
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index f95b9e5ba..5211ee027 100644
--- a/cmdline/apt-extracttemplates.cc
+++ b/cmdline/apt-extracttemplates.cc
@@ -33,6 +33,8 @@
#include <apt-pkg/dirstream.h>
#include <apt-pkg/mmap.h>
+#include <apt-private/private-cmndline.h>
+
#include <iostream>
#include <stdio.h>
#include <string.h>
@@ -215,15 +217,15 @@ bool DebFile::ParseInfo()
// ShowHelp - show a short help text /*{{{*/
// ---------------------------------------------------------------------
/* */
-static int ShowHelp(void)
+static bool ShowHelp(CommandLine &)
{
- ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
+ ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
COMMON_ARCH,__DATE__,__TIME__);
- if (_config->FindB("version") == true)
- return 0;
+ if (_config->FindB("version") == true)
+ return true;
- cout <<
+ cout <<
_("Usage: apt-extracttemplates file1 [file2 ...]\n"
"\n"
"apt-extracttemplates is a tool to extract config and template info\n"
@@ -234,7 +236,7 @@ static int ShowHelp(void)
" -t Set the temp dir\n"
" -c=? Read this configuration file\n"
" -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
- return 0;
+ return true;
}
/*}}}*/
// WriteFile - write the contents of the passed string to a file /*{{{*/
@@ -356,20 +358,10 @@ int main(int argc, const char **argv) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args,_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- CmdL.FileSize() == 0)
- return ShowHelp();
-
+ CommandLine::Dispatch Cmds[] = {{NULL, NULL}};
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
+
Go(CmdL);
// Print any errors or warnings found during operation
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index eca4a723b..a9053bdfd 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -1746,26 +1746,8 @@ int main(int argc,const char *argv[]) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(),_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- if (_config->FindB("version") == true)
- ShowHelp(CmdL);
-
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- _config->FindB("version") == true ||
- CmdL.FileSize() == 0)
- {
- ShowHelp(CmdL);
- return 0;
- }
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
// see if we are in simulate mode
CheckSimulateMode(CmdL);
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index 27abb2013..1b832f165 100644
--- a/cmdline/apt-helper.cc
+++ b/cmdline/apt-helper.cc
@@ -108,25 +108,8 @@ int main(int argc,const char *argv[]) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(),_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- if (_config->FindB("version") == true)
- ShowHelp(CmdL);
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- _config->FindB("version") == true ||
- CmdL.FileSize() == 0)
- {
- ShowHelp(CmdL);
- return 0;
- }
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
InitOutput();
diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc
index 92a4429e5..4fabeb02f 100644
--- a/cmdline/apt-internal-solver.cc
+++ b/cmdline/apt-internal-solver.cc
@@ -24,7 +24,9 @@
#include <apt-pkg/depcache.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/cacheiterators.h>
+
#include <apt-private/private-output.h>
+#include <apt-private/private-cmndline.h>
#include <string.h>
#include <iostream>
@@ -79,19 +81,8 @@ int main(int argc,const char *argv[]) /*{{{*/
// we really don't need anything
DropPrivileges();
- CommandLine CmdL(Args,_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false) {
- _error->DumpErrors();
- return 2;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- _config->FindB("version") == true) {
- ShowHelp(CmdL);
- return 1;
- }
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, NULL, Args, &_config, NULL, argc, argv, ShowHelp);
if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0)
{
diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc
index ed348358a..487f3d8a1 100644
--- a/cmdline/apt-mark.cc
+++ b/cmdline/apt-mark.cc
@@ -441,26 +441,8 @@ int main(int argc,const char *argv[]) /*{{{*/
setlocale(LC_ALL,"");
textdomain(PACKAGE);
- // Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(),_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- if (_config->FindB("version") == true)
- ShowHelp(CmdL);
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- _config->FindB("version") == true ||
- CmdL.FileSize() == 0)
- {
- ShowHelp(CmdL);
- return 0;
- }
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
// Deal with stdout not being a tty
if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc
index c2b11890a..9b66ad4db 100644
--- a/cmdline/apt-sortpkgs.cc
+++ b/cmdline/apt-sortpkgs.cc
@@ -23,6 +23,8 @@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/pkgsystem.h>
+#include <apt-private/private-cmndline.h>
+
#include <vector>
#include <algorithm>
#include <stdio.h>
@@ -142,12 +144,12 @@ static bool DoIt(string InFile)
// ShowHelp - Show the help text /*{{{*/
// ---------------------------------------------------------------------
/* */
-static int ShowHelp()
+static bool ShowHelp(CommandLine &)
{
ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
COMMON_ARCH,__DATE__,__TIME__);
if (_config->FindB("version") == true)
- return 0;
+ return true;
cout <<
_("Usage: apt-sortpkgs [options] file1 [file2 ...]\n"
@@ -161,7 +163,7 @@ static int ShowHelp()
" -c=? Read this configuration file\n"
" -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
- return 0;
+ return true;
}
/*}}}*/
int main(int argc,const char *argv[]) /*{{{*/
@@ -179,19 +181,9 @@ int main(int argc,const char *argv[]) /*{{{*/
textdomain(PACKAGE);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args,_config);
- if (pkgInitConfig(*_config) == false ||
- CmdL.Parse(argc,argv) == false ||
- pkgInitSystem(*_config,_system) == false)
- {
- _error->DumpErrors();
- return 100;
- }
-
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- CmdL.FileSize() == 0)
- return ShowHelp();
+ CommandLine::Dispatch Cmds[] = {{NULL, NULL}};
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
// Match the operation
for (unsigned int I = 0; I != CmdL.FileSize(); I++)
diff --git a/cmdline/apt.cc b/cmdline/apt.cc
index 2cfdf8e8e..056cd213f 100644
--- a/cmdline/apt.cc
+++ b/cmdline/apt.cc
@@ -119,15 +119,10 @@ int main(int argc, const char *argv[]) /*{{{*/
_config->CndSet("APT::Cmd::Show-Update-Stats", true);
// Parse the command line and initialize the package library
- CommandLine CmdL(Args.data(), _config);
- if (CmdL.Parse(argc, argv) == false ||
- pkgInitSystem(*_config, _system) == false)
- {
- _error->DumpErrors();
- return 100;
- }
+ CommandLine CmdL;
+ ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
- if(!isatty(STDOUT_FILENO) &&
+ if(!isatty(STDOUT_FILENO) &&
_config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
{
std::cerr << std::endl
@@ -138,15 +133,6 @@ int main(int argc, const char *argv[]) /*{{{*/
<< std::endl;
}
- // See if the help should be shown
- if (_config->FindB("help") == true ||
- _config->FindB("version") == true ||
- CmdL.FileSize() == 0)
- {
- ShowHelp(CmdL);
- return 0;
- }
-
// see if we are in simulate mode
CheckSimulateMode(CmdL);
diff --git a/cmdline/makefile b/cmdline/makefile
index b7c35ddd1..816038c3b 100644
--- a/cmdline/makefile
+++ b/cmdline/makefile
@@ -67,15 +67,15 @@ APT_DOMAIN:=apt-utils
# The apt-sortpkgs program
PROGRAM=apt-sortpkgs
-SLIBS = -lapt-pkg $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile
+SLIBS = -lapt-pkg -lapt-private $(INTLLIBS)
+LIB_MAKES = apt-pkg/makefile apt-private/makefile
SOURCE = apt-sortpkgs.cc
include $(PROGRAM_H)
# The apt-extracttemplates program
PROGRAM=apt-extracttemplates
-SLIBS = -lapt-pkg -lapt-inst $(INTLLIBS)
-LIB_MAKES = apt-pkg/makefile apt-inst/makefile
+SLIBS = -lapt-pkg -lapt-inst -lapt-private $(INTLLIBS)
+LIB_MAKES = apt-pkg/makefile apt-inst/makefile apt-private/makefile
SOURCE = apt-extracttemplates.cc
include $(PROGRAM_H)