]>
git.saurik.com Git - apt.git/blob - cmdline/apt-config.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-config.cc,v 1.5 1999/05/23 05:45:12 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)
34 if (I
[1] == 0 || strlen(I
[1]) == 0)
35 return _error
->Error("Arguments not in pairs");
37 // Check if the caller has requested a directory path
38 if (I
[1][strlen(I
[1])-1] == '/')
43 if (_config
->Exists(S
) == true)
44 cout
<< *I
<< "=\"" << _config
->FindDir(S
) << '"' << endl
;
47 if (_config
->Exists(I
[1]) == true)
48 cout
<< *I
<< "=\"" << _config
->Find(I
[1]) << '"' << endl
;
54 // ShowHelp - Show the help screen /*{{{*/
55 // ---------------------------------------------------------------------
59 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
60 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
61 if (_config
->FindB("version") == true)
64 cout
<< "Usage: apt-config [options] command" << endl
;
66 cout
<< "apt-config is a simple tool to read the APT config file" << endl
;
68 cout
<< "Commands:" << endl
;
69 cout
<< " shell - Shell mode" << endl
;
71 cout
<< "Options:" << endl
;
72 cout
<< " -h This help text." << endl
;
73 cout
<< " -c=? Read this configuration file" << endl
;
74 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
79 int main(int argc
,const char *argv
[])
81 CommandLine::Args Args
[] = {
82 {'h',"help","help",0},
83 {'v',"version","version",0},
84 {'c',"config-file",0,CommandLine::ConfigFile
},
85 {'o',"option",0,CommandLine::ArbItem
},
87 CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
},
90 // Parse the command line and initialize the package library
91 CommandLine
CmdL(Args
,_config
);
92 if (pkgInitialize(*_config
) == false ||
93 CmdL
.Parse(argc
,argv
) == false)
99 // See if the help should be shown
100 if (_config
->FindB("help") == true ||
101 CmdL
.FileSize() == 0)
104 // Match the operation
105 CmdL
.DispatchArg(Cmds
);
107 // Print any errors or warnings found during parsing
108 if (_error
->empty() == false)
110 bool Errors
= _error
->PendingError();
111 _error
->DumpErrors();
112 return Errors
== true?100:0;