]>
Commit | Line | Data |
---|---|---|
08e8f724 AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
83ab33fc | 3 | // $Id: cmndline.h,v 1.7 1999/10/31 06:32:28 jgg Exp $ |
08e8f724 AL |
4 | /* ###################################################################### |
5 | ||
6 | Command Line Class - Sophisticated command line parser | |
7 | ||
8 | This class provides a unified command line parser/option handliner/ | |
9 | configuration mechanism. It allows the caller to specify the option | |
10 | set and map the option set into the configuration class or other | |
11 | special functioning. | |
12 | ||
13 | Filenames are stripped from the option stream and put into their | |
14 | own array. | |
15 | ||
16 | The argument descriptor array can be initialized as: | |
17 | ||
18 | CommandLine::Args Args[] = | |
19 | {{'q',"quiet","apt::get::quiet",CommandLine::IntLevel}, | |
83ab33fc | 20 | {0,0,0,0}}; |
08e8f724 AL |
21 | |
22 | The flags mean, | |
23 | HasArg - Means the argument has a value | |
24 | IntLevel - Means the argument is an integer level indication, the | |
25 | following -qqqq (+3) -q5 (=5) -q=5 (=5) are valid | |
26 | Boolean - Means it is true/false or yes/no. | |
27 | -d (true) --no-d (false) --yes-d (true) | |
28 | --long (true) --no-long (false) --yes-long (true) | |
29 | -d=yes (true) -d=no (false) Words like enable, disable, | |
30 | true false, yes no and on off are recognized in logical | |
31 | places. | |
32 | InvBoolean - Same as boolean but the case with no specified sense | |
33 | (first case) is set to false. | |
34 | ConfigFile - Means this flag should be interprited as the name of | |
35 | a config file to read in at this point in option processing. | |
36 | Implies HasArg. | |
7365ff46 | 37 | ArbItem - Means the item is an arbitrary configuration string of |
83ab33fc AL |
38 | the form item=value, where item is passed directly |
39 | to the configuration class. | |
08e8f724 AL |
40 | The default, if the flags are 0 is to use Boolean |
41 | ||
42 | ##################################################################### */ | |
43 | /*}}}*/ | |
08e8f724 AL |
44 | #ifndef PKGLIB_CMNDLINE_H |
45 | #define PKGLIB_CMNDLINE_H | |
46 | ||
a02db58f DK |
47 | #include <apt-pkg/macros.h> |
48 | ||
b9dadc24 DK |
49 | #ifndef APT_8_CLEANER_HEADERS |
50 | #include <apt-pkg/configuration.h> | |
51 | #endif | |
52 | ||
472ff00e | 53 | class Configuration; |
08e8f724 AL |
54 | |
55 | class CommandLine | |
56 | { | |
57 | public: | |
58 | struct Args; | |
bc4af0b9 | 59 | struct Dispatch; |
cbbee23e | 60 | struct DispatchWithHelp; |
08e8f724 AL |
61 | |
62 | protected: | |
63 | ||
64 | Args *ArgList; | |
65 | Configuration *Conf; | |
0d47bd08 AL |
66 | bool HandleOpt(int &I,int argc,const char *argv[], |
67 | const char *&Opt,Args *A,bool PreceedeMatch = false); | |
2bb25574 | 68 | void static SaveInConfig(unsigned int const &argc, char const * const * const argv); |
0d47bd08 | 69 | |
08e8f724 AL |
70 | public: |
71 | ||
72 | enum AFlags | |
73 | { | |
74 | HasArg = (1 << 0), | |
75 | IntLevel = (1 << 1), | |
76 | Boolean = (1 << 2), | |
77 | InvBoolean = (1 << 3), | |
e1b74f61 AL |
78 | ConfigFile = (1 << 4) | HasArg, |
79 | ArbItem = (1 << 5) | HasArg | |
08e8f724 AL |
80 | }; |
81 | ||
82 | const char **FileList; | |
83 | ||
84 | bool Parse(int argc,const char **argv); | |
85 | void ShowHelp(); | |
a02db58f | 86 | unsigned int FileSize() const APT_PURE; |
b0b4efb9 | 87 | bool DispatchArg(Dispatch *List,bool NoMatch = true); |
e7e10e47 | 88 | bool DispatchArg(DispatchWithHelp const * const List,bool NoMatch = true); |
08e8f724 | 89 | |
b9179170 | 90 | static char const * GetCommand(Dispatch const * const Map, |
a02db58f | 91 | unsigned int const argc, char const * const * const argv) APT_PURE; |
cbbee23e DK |
92 | static char const * GetCommand(DispatchWithHelp const * const Map, |
93 | unsigned int const argc, char const * const * const argv) APT_PURE; | |
94 | ||
b9179170 MV |
95 | |
96 | static CommandLine::Args MakeArgs(char ShortOpt, char const *LongOpt, | |
a02db58f | 97 | char const *ConfName, unsigned long Flags) APT_CONST; |
b9179170 | 98 | |
ad7e0941 | 99 | CommandLine(); |
08e8f724 | 100 | CommandLine(Args *AList,Configuration *Conf); |
e1b74f61 | 101 | ~CommandLine(); |
08e8f724 AL |
102 | }; |
103 | ||
104 | struct CommandLine::Args | |
105 | { | |
106 | char ShortOpt; | |
107 | const char *LongOpt; | |
108 | const char *ConfName; | |
109 | unsigned long Flags; | |
110 | ||
111 | inline bool end() {return ShortOpt == 0 && LongOpt == 0;}; | |
e1b74f61 | 112 | inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;}; |
08e8f724 | 113 | }; |
bc4af0b9 AL |
114 | |
115 | struct CommandLine::Dispatch | |
116 | { | |
117 | const char *Match; | |
118 | bool (*Handler)(CommandLine &); | |
119 | }; | |
cbbee23e DK |
120 | struct CommandLine::DispatchWithHelp |
121 | { | |
122 | const char *Match; | |
123 | bool (*Handler)(CommandLine &); | |
124 | const char *Help; | |
125 | }; | |
bc4af0b9 | 126 | |
08e8f724 | 127 | #endif |