]>
git.saurik.com Git - apt.git/blob - cmdline/apt-config.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-config.cc,v 1.2 1998/11/27 01:52:57 jgg Exp $
4 /* ######################################################################
6 APT Config - Program to manipulate APT configuration files
8 This program will parse a config file and then do something with it.
11 shell - Shell mode. After this a series of word pairs should occure.
12 The first is the environment var to set and the second is
13 the key to set it from. Use like:
14 eval `apt-config shell QMode apt::QMode`
16 ##################################################################### */
18 // Include Files /*{{{*/
19 #include <apt-pkg/cmndline.h>
20 #include <apt-pkg/error.h>
21 #include <apt-pkg/init.h>
27 // DoShell - Handle the shell command /*{{{*/
28 // ---------------------------------------------------------------------
30 bool DoShell(CommandLine
&CmdL
)
32 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
+= 2)
35 return _error
->Error("Arguments not in pairs");
36 if (_config
->Exists(I
[1]) == true)
37 cout
<< *I
<< "=\"" << _config
->Find(I
[1]) << '"' << endl
;
43 // ShowHelp - Show the help screen /*{{{*/
44 // ---------------------------------------------------------------------
48 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
49 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
51 cout
<< "Usage: apt-config [options] command" << endl
;
53 cout
<< "apt-config is a simple tool to read the APT config file" << endl
;
55 cout
<< "Commands:" << endl
;
56 cout
<< " shell - Shell mode" << endl
;
58 cout
<< "Options:" << endl
;
59 cout
<< " -h This help text." << endl
;
60 cout
<< " -c=? Read this configuration file" << endl
;
61 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
66 int main(int argc
,const char *argv
[])
68 CommandLine::Args Args
[] = {
69 {'h',"help","help",0},
70 {'c',"config-file",0,CommandLine::ConfigFile
},
71 {'o',"option",0,CommandLine::ArbItem
},
73 CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
},
76 // Parse the command line and initialize the package library
77 CommandLine
CmdL(Args
,_config
);
78 if (pkgInitialize(*_config
) == false ||
79 CmdL
.Parse(argc
,argv
) == false)
85 // See if the help should be shown
86 if (_config
->FindB("help") == true ||
90 // Match the operation
91 CmdL
.DispatchArg(Cmds
);
93 // Print any errors or warnings found during parsing
94 if (_error
->empty() == false)
96 bool Errors
= _error
->PendingError();
98 return Errors
== true?100:0;