]>
git.saurik.com Git - apt.git/blob - cmdline/apt-config.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-config.cc,v 1.7 2001/02/20 07:03:17 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>
22 #include <apt-pkg/strutl.h>
31 // DoShell - Handle the shell command /*{{{*/
32 // ---------------------------------------------------------------------
34 bool DoShell(CommandLine
&CmdL
)
36 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
+= 2)
38 if (I
[1] == 0 || strlen(I
[1]) == 0)
39 return _error
->Error(_("Arguments not in pairs"));
42 if (key
.end()[-1] == '/') // old directory format
45 if (_config
->ExistsAny(key
.c_str()))
47 SubstVar(_config
->FindAny(key
.c_str()),"'","'\\''") << '\'' << endl
;
54 // DoDump - Dump the configuration space /*{{{*/
55 // ---------------------------------------------------------------------
57 bool DoDump(CommandLine
&CmdL
)
63 // ShowHelp - Show the help screen /*{{{*/
64 // ---------------------------------------------------------------------
68 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
69 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
70 if (_config
->FindB("version") == true)
74 _("Usage: apt-config [options] command\n"
76 "apt-config is a simple tool to read the APT config file\n"
79 " shell - Shell mode\n"
80 " dump - Show the configuration\n"
83 " -h This help text.\n"
84 " -c=? Read this configuration file\n"
85 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n");
90 int main(int argc
,const char *argv
[])
92 CommandLine::Args Args
[] = {
93 {'h',"help","help",0},
94 {'v',"version","version",0},
95 {'c',"config-file",0,CommandLine::ConfigFile
},
96 {'o',"option",0,CommandLine::ArbItem
},
98 CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
},
102 // Parse the command line and initialize the package library
103 CommandLine
CmdL(Args
,_config
);
104 if (pkgInitConfig(*_config
) == false ||
105 CmdL
.Parse(argc
,argv
) == false ||
106 pkgInitSystem(*_config
,_system
) == false)
108 _error
->DumpErrors();
112 // See if the help should be shown
113 if (_config
->FindB("help") == true ||
114 CmdL
.FileSize() == 0)
117 // Match the operation
118 CmdL
.DispatchArg(Cmds
);
120 // Print any errors or warnings found during parsing
121 if (_error
->empty() == false)
123 bool Errors
= _error
->PendingError();
124 _error
->DumpErrors();
125 return Errors
== true?100:0;