]>
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>
23 #include <apt-pkg/configuration.h>
24 #include <apt-pkg/aptconfiguration.h>
36 // DoShell - Handle the shell command /*{{{*/
37 // ---------------------------------------------------------------------
39 bool DoShell(CommandLine
&CmdL
)
41 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
+= 2)
43 if (I
[1] == 0 || strlen(I
[1]) == 0)
44 return _error
->Error(_("Arguments not in pairs"));
47 if (key
.end()[-1] == '/') // old directory format
50 if (_config
->ExistsAny(key
.c_str()))
52 SubstVar(_config
->FindAny(key
.c_str()),"'","'\\''") << '\'' << endl
;
59 // DoDump - Dump the configuration space /*{{{*/
60 // ---------------------------------------------------------------------
62 bool DoDump(CommandLine
&CmdL
)
68 // ShowHelp - Show the help screen /*{{{*/
69 // ---------------------------------------------------------------------
73 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
74 COMMON_ARCH
,__DATE__
,__TIME__
);
75 if (_config
->FindB("version") == true)
79 _("Usage: apt-config [options] command\n"
81 "apt-config is a simple tool to read the APT config file\n"
84 " shell - Shell mode\n"
85 " dump - Show the configuration\n"
88 " -h This help text.\n"
89 " -c=? Read this configuration file\n"
90 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
94 int main(int argc
,const char *argv
[]) /*{{{*/
96 CommandLine::Args Args
[] = {
97 {'h',"help","help",0},
98 {'v',"version","version",0},
99 {'c',"config-file",0,CommandLine::ConfigFile
},
100 {'o',"option",0,CommandLine::ArbItem
},
102 CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
},
106 // Set up gettext support
107 setlocale(LC_ALL
,"");
110 // Parse the command line and initialize the package library
111 CommandLine
CmdL(Args
,_config
);
112 if (pkgInitConfig(*_config
) == false ||
113 CmdL
.Parse(argc
,argv
) == false ||
114 pkgInitSystem(*_config
,_system
) == false)
116 _error
->DumpErrors();
120 // See if the help should be shown
121 if (_config
->FindB("help") == true ||
122 CmdL
.FileSize() == 0)
125 std::vector
<std::string
> const langs
= APT::Configuration::getLanguages(true);
126 _config
->Clear("Acquire::Languages");
127 for (std::vector
<std::string
>::const_iterator l
= langs
.begin(); l
!= langs
.end(); ++l
)
128 _config
->Set("Acquire::Languages::", *l
);
130 std::vector
<std::string
> const archs
= APT::Configuration::getArchitectures();
131 _config
->Clear("APT::Architectures");
132 for (std::vector
<std::string
>::const_iterator a
= archs
.begin(); a
!= archs
.end(); ++a
)
133 _config
->Set("APT::Architectures::", *a
);
135 // Match the operation
136 CmdL
.DispatchArg(Cmds
);
138 // Print any errors or warnings found during parsing
139 if (_error
->empty() == false)
141 bool Errors
= _error
->PendingError();
142 _error
->DumpErrors();
143 return Errors
== true?100:0;