Apache Mesos
flags.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_FLAGS_HPP__
14 #define __STOUT_FLAGS_HPP__
15 
16 #include <stout/flags/flags.hpp>
17 
18 // An abstraction for application/library "flags". An example is
19 // probably best:
20 // -------------------------------------------------------------
21 // class MyFlags : public virtual FlagsBase // Use 'virtual' for composition!
22 // {
23 // public:
24 // MyFlags()
25 // {
26 // add(&MyFlags::debug,
27 // "debug",
28 // "Help string for debug",
29 // false);
30 //
31 // add(&MyFlags::name,
32 // "name",
33 // "Help string for name");
34 // }
35 
36 // bool debug;
37 // Option<string> name;
38 // };
39 //
40 // ...
41 //
42 // map<string, Option<string>> values;
43 // values["no-debug"] = None(); // --no-debug
44 // values["debug"] = None(); // --debug
45 // values["debug"] = Some("true"); // --debug=true
46 // values["debug"] = Some("false"); // --debug=false
47 // values["name"] = Some("frank"); // --name=frank
48 //
49 // MyFlags flags;
50 // flags.load(values);
51 // flags.name.isSome() ...
52 // flags.debug ...
53 // -------------------------------------------------------------
54 //
55 // You can also compose flags provided that each has used "virtual
56 // inheritance":
57 // -------------------------------------------------------------
58 // class MyFlags : public virtual MyFlags1, public virtual MyFlags2 {};
59 //
60 // MyFlags flags;
61 // flags.add(...); // Any other flags you want to throw in there.
62 // flags.load(values);
63 // flags.flag_from_myflags1 ...
64 // flags.flag_from_myflags2 ...
65 // -------------------------------------------------------------
66 //
67 // "Fail early, fail often":
68 //
69 // You cannot add duplicate flags, this is checked for you at compile
70 // time for composite flags (e.g., Flag<MyFlags1, MyFlags2>) and also
71 // checked at runtime for any other flags added via inheritance or
72 // Flags::add(...).
73 //
74 // Flags that cannot be loaded (e.g., attempting to use the 'no-'
75 // prefix for a flag that is not boolean) will print a message to
76 // standard error and abort the process.
77 
78 // TODO(benh): Provide a boolean which specifies whether or not to
79 // abort on duplicates or load errors.
80 
81 #endif // __STOUT_FLAGS_HPP__