]>
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 | ||
13500573 | 47 | |
08e8f724 AL |
48 | |
49 | #include <apt-pkg/configuration.h> | |
50 | ||
51 | class CommandLine | |
52 | { | |
53 | public: | |
54 | struct Args; | |
bc4af0b9 | 55 | struct Dispatch; |
08e8f724 AL |
56 | |
57 | protected: | |
58 | ||
59 | Args *ArgList; | |
60 | Configuration *Conf; | |
0d47bd08 AL |
61 | bool HandleOpt(int &I,int argc,const char *argv[], |
62 | const char *&Opt,Args *A,bool PreceedeMatch = false); | |
2bb25574 | 63 | void static SaveInConfig(unsigned int const &argc, char const * const * const argv); |
0d47bd08 | 64 | |
08e8f724 AL |
65 | public: |
66 | ||
67 | enum AFlags | |
68 | { | |
69 | HasArg = (1 << 0), | |
70 | IntLevel = (1 << 1), | |
71 | Boolean = (1 << 2), | |
72 | InvBoolean = (1 << 3), | |
e1b74f61 AL |
73 | ConfigFile = (1 << 4) | HasArg, |
74 | ArbItem = (1 << 5) | HasArg | |
08e8f724 AL |
75 | }; |
76 | ||
77 | const char **FileList; | |
78 | ||
79 | bool Parse(int argc,const char **argv); | |
80 | void ShowHelp(); | |
e1b74f61 | 81 | unsigned int FileSize() const; |
b0b4efb9 | 82 | bool DispatchArg(Dispatch *List,bool NoMatch = true); |
08e8f724 AL |
83 | |
84 | CommandLine(Args *AList,Configuration *Conf); | |
e1b74f61 | 85 | ~CommandLine(); |
08e8f724 AL |
86 | }; |
87 | ||
88 | struct CommandLine::Args | |
89 | { | |
90 | char ShortOpt; | |
91 | const char *LongOpt; | |
92 | const char *ConfName; | |
93 | unsigned long Flags; | |
94 | ||
95 | inline bool end() {return ShortOpt == 0 && LongOpt == 0;}; | |
e1b74f61 | 96 | inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;}; |
08e8f724 | 97 | }; |
bc4af0b9 AL |
98 | |
99 | struct CommandLine::Dispatch | |
100 | { | |
101 | const char *Match; | |
102 | bool (*Handler)(CommandLine &); | |
103 | }; | |
104 | ||
08e8f724 | 105 | #endif |