apt: apt-pkg/contrib/cmndline.h Source File

apt 2.9.8 commandline package manager

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