]>
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 /*{{{*/
21 #include <apt-pkg/cmndline.h>
22 #include <apt-pkg/error.h>
23 #include <apt-pkg/init.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/configuration.h>
26 #include <apt-pkg/aptconfiguration.h>
27 #include <apt-pkg/pkgsystem.h>
38 // DoShell - Handle the shell command /*{{{*/
39 // ---------------------------------------------------------------------
41 bool DoShell(CommandLine
&CmdL
)
43 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
+= 2)
45 if (I
[1] == 0 || strlen(I
[1]) == 0)
46 return _error
->Error(_("Arguments not in pairs"));
49 if (key
.end()[-1] == '/') // old directory format
52 if (_config
->ExistsAny(key
.c_str()))
54 SubstVar(_config
->FindAny(key
.c_str()),"'","'\\''") << '\'' << endl
;
61 // DoDump - Dump the configuration space /*{{{*/
62 // ---------------------------------------------------------------------
64 bool DoDump(CommandLine
&CmdL
)
70 // ShowHelp - Show the help screen /*{{{*/
71 // ---------------------------------------------------------------------
75 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
76 COMMON_ARCH
,__DATE__
,__TIME__
);
77 if (_config
->FindB("version") == true)
81 _("Usage: apt-config [options] command\n"
83 "apt-config is a simple tool to read the APT config file\n"
86 " shell - Shell mode\n"
87 " dump - Show the configuration\n"
90 " -h This help text.\n"
91 " -c=? Read this configuration file\n"
92 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
96 int main(int argc
,const char *argv
[]) /*{{{*/
98 CommandLine::Args Args
[] = {
99 {'h',"help","help",0},
100 {'v',"version","version",0},
101 {'c',"config-file",0,CommandLine::ConfigFile
},
102 {'o',"option",0,CommandLine::ArbItem
},
104 CommandLine::Dispatch Cmds
[] = {{"shell",&DoShell
},
108 // Set up gettext support
109 setlocale(LC_ALL
,"");
112 // Parse the command line and initialize the package library
113 CommandLine
CmdL(Args
,_config
);
114 if (pkgInitConfig(*_config
) == false ||
115 CmdL
.Parse(argc
,argv
) == false ||
116 pkgInitSystem(*_config
,_system
) == false)
118 _error
->DumpErrors();
122 // See if the help should be shown
123 if (_config
->FindB("help") == true ||
124 CmdL
.FileSize() == 0)
127 std::vector
<std::string
> const langs
= APT::Configuration::getLanguages(true);
128 _config
->Clear("Acquire::Languages");
129 for (std::vector
<std::string
>::const_iterator l
= langs
.begin(); l
!= langs
.end(); ++l
)
130 _config
->Set("Acquire::Languages::", *l
);
132 std::vector
<std::string
> const archs
= APT::Configuration::getArchitectures();
133 _config
->Clear("APT::Architectures");
134 for (std::vector
<std::string
>::const_iterator a
= archs
.begin(); a
!= archs
.end(); ++a
)
135 _config
->Set("APT::Architectures::", *a
);
137 // Match the operation
138 CmdL
.DispatchArg(Cmds
);
140 // Print any errors or warnings found during parsing
141 if (_error
->empty() == false)
143 bool Errors
= _error
->PendingError();
144 _error
->DumpErrors();
145 return Errors
== true?100:0;