]> git.saurik.com Git - apt.git/blame - cmdline/apt-config.cc
new quiet level -qq for apt to hide progress output
[apt.git] / cmdline / apt-config.cc
CommitLineData
7a1b1f8b
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
8f312f45 3// $Id: apt-config.cc,v 1.11 2003/01/11 07:18:44 jgg Exp $
7a1b1f8b
AL
4/* ######################################################################
5
6 APT Config - Program to manipulate APT configuration files
7
8 This program will parse a config file and then do something with it.
9
10 Commands:
1e3f4083 11 shell - Shell mode. After this a series of word pairs should occur.
7a1b1f8b
AL
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`
15
16 ##################################################################### */
17 /*}}}*/
18// Include Files /*{{{*/
ea542140
DK
19#include<config.h>
20
7a1b1f8b
AL
21#include <apt-pkg/cmndline.h>
22#include <apt-pkg/error.h>
23#include <apt-pkg/init.h>
b2e465d6 24#include <apt-pkg/strutl.h>
aa833344
DK
25#include <apt-pkg/configuration.h>
26#include <apt-pkg/aptconfiguration.h>
472ff00e 27#include <apt-pkg/pkgsystem.h>
7a1b1f8b
AL
28
29#include <iostream>
b2e465d6 30#include <string>
aa833344 31#include <vector>
453b82a3 32#include <string.h>
ea542140 33
b9179170 34#include <apt-private/private-cmndline.h>
e7e10e47 35#include <apt-private/private-main.h>
b9179170 36
ea542140 37#include <apti18n.h>
7a1b1f8b 38 /*}}}*/
8f312f45 39using namespace std;
7a1b1f8b
AL
40
41// DoShell - Handle the shell command /*{{{*/
42// ---------------------------------------------------------------------
43/* */
c3ccac92 44static bool DoShell(CommandLine &CmdL)
7a1b1f8b
AL
45{
46 for (const char **I = CmdL.FileList + 1; *I != 0; I += 2)
47 {
e42eb508 48 if (I[1] == 0 || strlen(I[1]) == 0)
b2e465d6 49 return _error->Error(_("Arguments not in pairs"));
e42eb508 50
b2e465d6
AL
51 string key = I[1];
52 if (key.end()[-1] == '/') // old directory format
53 key.append("d");
54
55 if (_config->ExistsAny(key.c_str()))
56 cout << *I << "='" <<
57 SubstVar(_config->FindAny(key.c_str()),"'","'\\''") << '\'' << endl;
e42eb508 58
7a1b1f8b
AL
59 }
60
314037ba
AL
61 return true;
62}
63 /*}}}*/
64// DoDump - Dump the configuration space /*{{{*/
65// ---------------------------------------------------------------------
66/* */
c3ccac92 67static bool DoDump(CommandLine &CmdL)
314037ba 68{
a8813606
DK
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);
73 else
74 for (const char **I = CmdL.FileList + 1; *I != 0; ++I)
75 _config->Dump(cout, *I, format.c_str(), empty);
7a1b1f8b
AL
76 return true;
77}
78 /*}}}*/
79// ShowHelp - Show the help screen /*{{{*/
80// ---------------------------------------------------------------------
81/* */
cbbee23e 82static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
7a1b1f8b 83{
249aec3b 84 ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
04aa15a8 85 if (_config->FindB("version") == true)
b9179170 86 return true;
249aec3b 87
cbbee23e
DK
88 std::cout <<
89 _("Usage: apt-config [options] command\n"
b2e465d6 90 "\n"
cbbee23e
DK
91 "apt-config is a simple tool to read the APT config file\n")
92 << std::endl
93 << _("Commands:") << std::endl;
94 for (; Cmds->Handler != nullptr; ++Cmds)
95 {
96 if (Cmds->Help == nullptr)
97 continue;
98 std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl;
99 }
100
101 std::cout << std::endl <<
102 _("Options:\n"
103 " -h This help text.\n"
104 " -c=? Read this configuration file\n"
a2884e32 105 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
b9179170 106 return true;
7a1b1f8b
AL
107}
108 /*}}}*/
92fcbfc1 109int main(int argc,const char *argv[]) /*{{{*/
7a1b1f8b 110{
e7e10e47
DK
111 InitLocale();
112
cbbee23e
DK
113 CommandLine::DispatchWithHelp Cmds[] = {
114 {"shell", &DoShell, _("get configuration values via shell evaluation")},
115 {"dump", &DoDump, _("show the active configuration setting")},
116 {nullptr, nullptr, nullptr}
117 };
67111687 118
7a1b1f8b 119 // Parse the command line and initialize the package library
ad7e0941 120 CommandLine CmdL;
e7e10e47 121 ParseCommandLine(CmdL, Cmds, "apt-config", &_config, &_system, argc, argv, ShowHelp);
7a1b1f8b 122
aa833344
DK
123 std::vector<std::string> const langs = APT::Configuration::getLanguages(true);
124 _config->Clear("Acquire::Languages");
125 for (std::vector<std::string>::const_iterator l = langs.begin(); l != langs.end(); ++l)
126 _config->Set("Acquire::Languages::", *l);
127
128 std::vector<std::string> const archs = APT::Configuration::getArchitectures();
129 _config->Clear("APT::Architectures");
130 for (std::vector<std::string>::const_iterator a = archs.begin(); a != archs.end(); ++a)
131 _config->Set("APT::Architectures::", *a);
132
8e16d8c3
DK
133 std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
134 _config->Clear("APT::Compressor");
135 string conf = "APT::Compressor::";
136 for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin(); c != compressors.end(); ++c)
137 {
138 string comp = conf + c->Name + "::";
139 _config->Set(comp + "Name", c->Name);
140 _config->Set(comp + "Extension", c->Extension);
141 _config->Set(comp + "Binary", c->Binary);
142 _config->Set(std::string(comp + "Cost").c_str(), c->Cost);
143 for (std::vector<std::string>::const_iterator a = c->CompressArgs.begin(); a != c->CompressArgs.end(); ++a)
144 _config->Set(comp + "CompressArg::", *a);
145 for (std::vector<std::string>::const_iterator a = c->UncompressArgs.begin(); a != c->UncompressArgs.end(); ++a)
146 _config->Set(comp + "UncompressArg::", *a);
147 }
148
ce7f128c
DK
149 std::vector<std::string> const profiles = APT::Configuration::getBuildProfiles();
150 _config->Clear("APT::Build-Profiles");
151 for (std::vector<std::string>::const_iterator p = profiles.begin(); p != profiles.end(); ++p)
152 _config->Set("APT::Build-Profiles::", *p);
153
e7e10e47 154 return DispatchCommandLine(CmdL, Cmds);
7a1b1f8b 155}
92fcbfc1 156 /*}}}*/