]>
git.saurik.com Git - apt.git/blob - cmdline/apt-config.cc
eb096440a2fca88448896b7e974979c536c27988
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 occur.
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>
34 #include <apt-private/private-cmndline.h>
35 #include <apt-private/private-main.h>
41 // DoShell - Handle the shell command /*{{{*/
42 // ---------------------------------------------------------------------
44 static bool DoShell(CommandLine
&CmdL
)
46 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
+= 2)
48 if (I
[1] == 0 || strlen(I
[1]) == 0)
49 return _error
->Error(_("Arguments not in pairs"));
52 if (key
.end()[-1] == '/') // old directory format
55 if (_config
->ExistsAny(key
.c_str()))
57 SubstVar(_config
->FindAny(key
.c_str()),"'","'\\''") << '\'' << endl
;
64 // DoDump - Dump the configuration space /*{{{*/
65 // ---------------------------------------------------------------------
67 static bool DoDump(CommandLine
&CmdL
)
69 bool const empty
= _config
->FindB("APT::Config::Dump::EmptyValue", true);
70 std::string
const format
= _config
->Find("APT::Config::Dump::Format", "%f \"%v\";\n");
71 if (CmdL
.FileSize() == 1)
72 _config
->Dump(cout
, NULL
, format
.c_str(), empty
);
74 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; ++I
)
75 _config
->Dump(cout
, *I
, format
.c_str(), empty
);
79 bool ShowHelp(CommandLine
&, aptDispatchWithHelp
const * Cmds
) /*{{{*/
82 _("Usage: apt-config [options] command\n"
84 "apt-config is a simple tool to read the APT config file\n")
86 ShowHelpListCommands(Cmds
);
87 std::cout
<< std::endl
<<
89 " -h This help text.\n"
90 " -c=? Read this configuration file\n"
91 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
95 std::vector
<aptDispatchWithHelp
> GetCommands() /*{{{*/
98 {"shell", &DoShell
, _("get configuration values via shell evaluation")},
99 {"dump", &DoDump
, _("show the active configuration setting")},
100 {nullptr, nullptr, nullptr}
104 int main(int argc
,const char *argv
[]) /*{{{*/
108 // Parse the command line and initialize the package library
110 auto const Cmds
= ParseCommandLine(CmdL
, APT_CMD::APT_CONFIG
, &_config
, &_system
, argc
, argv
);
112 std::vector
<std::string
> const langs
= APT::Configuration::getLanguages(true);
113 _config
->Clear("Acquire::Languages");
114 for (std::vector
<std::string
>::const_iterator l
= langs
.begin(); l
!= langs
.end(); ++l
)
115 _config
->Set("Acquire::Languages::", *l
);
117 std::vector
<std::string
> const archs
= APT::Configuration::getArchitectures();
118 _config
->Clear("APT::Architectures");
119 for (std::vector
<std::string
>::const_iterator a
= archs
.begin(); a
!= archs
.end(); ++a
)
120 _config
->Set("APT::Architectures::", *a
);
122 std::vector
<APT::Configuration::Compressor
> const compressors
= APT::Configuration::getCompressors();
123 _config
->Clear("APT::Compressor");
124 string conf
= "APT::Compressor::";
125 for (std::vector
<APT::Configuration::Compressor
>::const_iterator c
= compressors
.begin(); c
!= compressors
.end(); ++c
)
127 string comp
= conf
+ c
->Name
+ "::";
128 _config
->Set(comp
+ "Name", c
->Name
);
129 _config
->Set(comp
+ "Extension", c
->Extension
);
130 _config
->Set(comp
+ "Binary", c
->Binary
);
131 _config
->Set(std::string(comp
+ "Cost").c_str(), c
->Cost
);
132 for (std::vector
<std::string
>::const_iterator a
= c
->CompressArgs
.begin(); a
!= c
->CompressArgs
.end(); ++a
)
133 _config
->Set(comp
+ "CompressArg::", *a
);
134 for (std::vector
<std::string
>::const_iterator a
= c
->UncompressArgs
.begin(); a
!= c
->UncompressArgs
.end(); ++a
)
135 _config
->Set(comp
+ "UncompressArg::", *a
);
138 std::vector
<std::string
> const profiles
= APT::Configuration::getBuildProfiles();
139 _config
->Clear("APT::Build-Profiles");
140 for (std::vector
<std::string
>::const_iterator p
= profiles
.begin(); p
!= profiles
.end(); ++p
)
141 _config
->Set("APT::Build-Profiles::", *p
);
143 return DispatchCommandLine(CmdL
, Cmds
);