]> git.saurik.com Git - apt.git/blame - cmdline/apt-config.cc
woops, extra space, fixed.
[apt.git] / cmdline / apt-config.cc
CommitLineData
7a1b1f8b
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
314037ba 3// $Id: apt-config.cc,v 1.6 1999/06/06 05:52:37 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:
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`
15
16 ##################################################################### */
17 /*}}}*/
18// Include Files /*{{{*/
19#include <apt-pkg/cmndline.h>
20#include <apt-pkg/error.h>
21#include <apt-pkg/init.h>
22#include "config.h"
23
24#include <iostream>
25 /*}}}*/
26
27// DoShell - Handle the shell command /*{{{*/
28// ---------------------------------------------------------------------
29/* */
30bool DoShell(CommandLine &CmdL)
31{
32 for (const char **I = CmdL.FileList + 1; *I != 0; I += 2)
33 {
e42eb508 34 if (I[1] == 0 || strlen(I[1]) == 0)
7a1b1f8b 35 return _error->Error("Arguments not in pairs");
e42eb508
AL
36
37 // Check if the caller has requested a directory path
38 if (I[1][strlen(I[1])-1] == '/')
39 {
40 char S[300];
41 strcpy(S,I[1]);
42 S[strlen(S)-1] = 0;
43 if (_config->Exists(S) == true)
44 cout << *I << "=\"" << _config->FindDir(S) << '"' << endl;
45 }
46
7a1b1f8b
AL
47 if (_config->Exists(I[1]) == true)
48 cout << *I << "=\"" << _config->Find(I[1]) << '"' << endl;
49 }
50
314037ba
AL
51 return true;
52}
53 /*}}}*/
54// DoDump - Dump the configuration space /*{{{*/
55// ---------------------------------------------------------------------
56/* */
57bool DoDump(CommandLine &CmdL)
58{
59 _config->Dump();
7a1b1f8b
AL
60 return true;
61}
62 /*}}}*/
63// ShowHelp - Show the help screen /*{{{*/
64// ---------------------------------------------------------------------
65/* */
66int ShowHelp()
67{
68 cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
69 " compiled on " << __DATE__ << " " << __TIME__ << endl;
04aa15a8
AL
70 if (_config->FindB("version") == true)
71 return 100;
7a1b1f8b
AL
72
73 cout << "Usage: apt-config [options] command" << endl;
74 cout << endl;
75 cout << "apt-config is a simple tool to read the APT config file" << endl;
76 cout << endl;
77 cout << "Commands:" << endl;
78 cout << " shell - Shell mode" << endl;
314037ba 79 cout << " dump - Show the configuration" << endl;
7a1b1f8b
AL
80 cout << endl;
81 cout << "Options:" << endl;
82 cout << " -h This help text." << endl;
83 cout << " -c=? Read this configuration file" << endl;
7974b907 84 cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
7a1b1f8b
AL
85 return 100;
86}
87 /*}}}*/
88
89int main(int argc,const char *argv[])
90{
91 CommandLine::Args Args[] = {
92 {'h',"help","help",0},
04aa15a8 93 {'v',"version","version",0},
7a1b1f8b
AL
94 {'c',"config-file",0,CommandLine::ConfigFile},
95 {'o',"option",0,CommandLine::ArbItem},
96 {0,0,0,0}};
83d89a9f 97 CommandLine::Dispatch Cmds[] = {{"shell",&DoShell},
314037ba 98 {"dump",&DoDump},
83d89a9f 99 {0,0}};
7a1b1f8b
AL
100
101 // Parse the command line and initialize the package library
102 CommandLine CmdL(Args,_config);
103 if (pkgInitialize(*_config) == false ||
104 CmdL.Parse(argc,argv) == false)
105 {
106 _error->DumpErrors();
107 return 100;
108 }
109
110 // See if the help should be shown
111 if (_config->FindB("help") == true ||
112 CmdL.FileSize() == 0)
113 return ShowHelp();
7a1b1f8b 114
83d89a9f
AL
115 // Match the operation
116 CmdL.DispatchArg(Cmds);
117
7a1b1f8b
AL
118 // Print any errors or warnings found during parsing
119 if (_error->empty() == false)
120 {
121 bool Errors = _error->PendingError();
122 _error->DumpErrors();
123 return Errors == true?100:0;
124 }
125
126 return 0;
127}