Thu, 24 Jul 2014 17:01:23 +0300
- and --help works now correctly too
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | Copyright 2014 Teemu Piippo |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | All rights reserved. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | Redistribution and use in source and binary forms, with or without |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | modification, are permitted provided that the following conditions |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | are met: |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | 1. Redistributions of source code must retain the above copyright |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | notice, this list of conditions and the following disclaimer. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | 2. Redistributions in binary form must reproduce the above copyright |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | notice, this list of conditions and the following disclaimer in the |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | documentation and/or other materials provided with the distribution. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | 3. The name of the author may not be used to endorse or promote products |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | derived from this software without specific prior written permission. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | */ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | #include "commandline.h" |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | // _________________________________________________________________________________________________ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | // |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | CommandLine::~CommandLine() |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | for (CommandLineOption* opt : _options) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | delete opt; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | // _________________________________________________________________________________________________ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | // |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
41 | StringList CommandLine::process (int const argc, char* argv[]) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | StringList args; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | |
142
1f5518dd8146
- and --help works now correctly too
Teemu Piippo <crimsondusk64@gmail.com>
parents:
141
diff
changeset
|
45 | for (int argn = 1; argn < argc; ++argn) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
47 | String const arg (argv[argn]); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | if (arg == "--") |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // terminating option - write everything to args and be done with it. |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | while (++argn < argc) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | args << argv[argn]; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | break; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
58 | if (arg[0] != '-' or arg[1] == '\0') |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | // non-option argument - pass to result |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | args << arg; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | continue; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
65 | if (arg[1] != '-' and arg[1] != '\0') |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | // short-form options |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | for (int i = 1; i < arg.length(); ++i) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | CommandLineOption** optionptr = _options.find ([&](CommandLineOption* const& a) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | return arg[i] == a->shortform(); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | }); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | if (not optionptr) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | error ("unknown option -%1", arg[i]); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | CommandLineOption* option = *optionptr; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | if (option->isOfType<bool>()) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | // Bool options need no parameters |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | option->handleValue (""); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | } |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
85 | else |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
86 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
87 | // Ensure we got a valid parameter coming up |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
88 | if (argn == argc - 1) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
89 | error ("option -%1 requires a parameter", option->describe()); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
91 | if (i != arg.length() - 1) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
92 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
93 | error ("option %1 requires a parameter but has option -%2 stacked on", |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | option->describe(), arg[i + 1]); |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
95 | } |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
97 | option->handleValue (argv[++argn]); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
98 | } |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | else |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // long-form options |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | String name, value; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | int idx = arg.firstIndexOf ("=", 2); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | if (idx != -1) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | name = arg.mid (2, idx); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | value = arg.mid (idx + 1); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | else |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | name = arg.mid (2); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | CommandLineOption** optionptr = _options.find ([&](CommandLineOption* const& a) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | return a->longform() == name; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | }); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | if (not optionptr) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | error ("unknown option --%1", name); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | if ((*optionptr)->isOfType<bool>() and not value.isEmpty()) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | error ("option %1 does not take a value", (*optionptr)->describe()); |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
129 | |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | (*optionptr)->handleValue (value); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | return args; |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | // _________________________________________________________________________________________________ |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | // |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
139 | String CommandLine::describeOptions() const |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
140 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
141 | StringList lines; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
142 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
143 | for (CommandLineOption* option : _options) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
144 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
145 | String line (" "); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
146 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
147 | if (option->shortform() != '\0') |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
148 | line += String ({'-', option->shortform(), '\0'}); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
149 | else |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
150 | line += " "; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
151 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
152 | line += " "; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
153 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
154 | if (not option->longform().isEmpty()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
155 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
156 | line += "--" + option->longform(); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
157 | String description (option->describeArgument()); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
158 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
159 | if (not description.isEmpty()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
160 | line += "=" + description; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
161 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
162 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
163 | lines << line; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
164 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
165 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
166 | int maxlength (0); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
167 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
168 | for (String& line : lines) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
169 | maxlength = max (maxlength, line.length()); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
170 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
171 | maxlength += 2; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
172 | ASSERT_EQ (lines.size(), _options.size()); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
173 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
174 | for (int i = 0; i < lines.size(); ++i) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
175 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
176 | while (lines[i].length() < maxlength) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
177 | lines[i] += " "; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
178 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
179 | lines[i] += _options[i]->description(); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
180 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
181 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
182 | StringList extralines; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
183 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
184 | for (CommandLineOption* option : _options) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
185 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
186 | String extradata = option->describeExtra(); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
187 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
188 | if (not extradata.isEmpty()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
189 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
190 | if (extralines.isEmpty()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
191 | extralines << ""; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
192 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
193 | extralines << extradata; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
194 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
195 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
196 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
197 | lines.merge (extralines); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
198 | String result (lines.join ("\n")); |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
199 | return result; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
200 | } |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
201 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
202 | // _________________________________________________________________________________________________ |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
203 | // |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
204 | void CommandLineOption::handleValue (const String& a) |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | if (isOfType<bool>()) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
208 | pointer().setValue (true); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | elif (isOfType<int>()) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | bool ok; |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
213 | pointer().setValue (a.toLong (&ok)); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
214 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
215 | if (not ok) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | error ("bad integral value passed to %1", describe()); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
218 | elif (isOfType<String>()) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | { |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
220 | pointer().setValue (a); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | elif (isOfType<double>()) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
224 | bool ok; |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
225 | pointer().setValue (a.toDouble (&ok)); |
139
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
226 | |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | if (not ok) |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | error ("bad floating-point value passed to %1", describe()); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
229 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
230 | else |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
231 | { |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
232 | error ("OMGWTFBBQ: %1 has an invalid type index", describe()); |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | } |
cf11621ae422
- added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | } |
141
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
235 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
236 | // _________________________________________________________________________________________________ |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
237 | // |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
238 | String CommandLineOption::describeArgument() const |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
239 | { |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
240 | if (isOfType<int>()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
241 | return "INTEGER"; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
242 | elif (isOfType<String>()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
243 | return "STRING"; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
244 | elif (isOfType<double>()) |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
245 | return "FLOAT"; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
246 | |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
247 | return ""; |
68d60e2cfa76
- now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
139
diff
changeset
|
248 | } |