]>
git.saurik.com Git - apt.git/blob - cmdline/apt-config.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-config.cc,v 1.11 2003/01/11 07:18:44 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>
33 // DoShell - Handle the shell command /*{{{*/
34 // ---------------------------------------------------------------------
36 bool DoShell(CommandLine
&CmdL
)
38 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
+= 2)
40 if (I
[1] == 0 || strlen(I
[1]) == 0)
41 return _error
->Error(_("Arguments not in pairs"));
44 if (key
.end()[-1] == '/') // old directory format
47 if (_config
->ExistsAny(key
.c_str()))
49 SubstVar(_config
->FindAny(key
.c_str()),"'","'\\''") << '\'' << endl
;
56 // DoDump - Dump the configuration space /*{{{*/
57 // ---------------------------------------------------------------------
59 bool DoDump(CommandLine
&CmdL
)
65 // ShowHelp - Show the help screen /*{{{*/
66 // ---------------------------------------------------------------------
70 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
71 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
72 if (_config
->FindB("version") == true)
76 _("Usage: apt-config [options] command\n"
78 "apt-config is a simple tool to read the APT config file\n"
81 " shell - Shell mode\n"
82 " dump - Show the configuration\n"
85 " -h This help text.\n"
86 " -c=? Read this configuration file\n"
87 " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp\n");
92 int main(int argc
,const char *argv
[])
94 CommandLine::Args Args
[] = {
95 {'h',"help","help",0},
96 {'v',"version","version",0},
97 {'c',"config-file",0,CommandLine::ConfigFile
},
98 {'o',"option",0,CommandLine::ArbItem
},
100 CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
},
104 // Set up gettext support
105 setlocale(LC_ALL
,"");
108 // Parse the command line and initialize the package library
109 CommandLine
CmdL(Args
,_config
);
110 if (pkgInitConfig(*_config
) == false ||
111 CmdL
.Parse(argc
,argv
) == false ||
112 pkgInitSystem(*_config
,_system
) == false)
114 _error
->DumpErrors();
118 // See if the help should be shown
119 if (_config
->FindB("help") == true ||
120 CmdL
.FileSize() == 0)
123 // Match the operation
124 CmdL
.DispatchArg(Cmds
);
126 // Print any errors or warnings found during parsing
127 if (_error
->empty() == false)
129 bool Errors
= _error
->PendingError();
130 _error
->DumpErrors();
131 return Errors
== true?100:0;