The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
commandline_options.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2016 by Lukasz Dobrogowski <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef COMMANDLINE_OPTIONS_HPP_INCLUDED
16 #define COMMANDLINE_OPTIONS_HPP_INCLUDED
17 
18 #include <boost/optional.hpp> // for optional
19 #include <boost/program_options/options_description.hpp>
20 #include <boost/tuple/tuple.hpp> // for tuple
21 #include <iosfwd> // for ostream
22 #include <string> // for string
23 #include <vector> // for vector
24 
26 {
27 public:
29 };
30 
32 {
33 public:
35  const std::string& expected_format);
36 };
37 
38 class config;
39 
41 {
42 /// To be used for printing help to the commandline.
43 friend std::ostream& operator<<(std::ostream &os, const commandline_options& cmdline_opts);
44 
45 public:
46  commandline_options(const std::vector<std::string>& args);
47 
48  config to_config() const; /* Used by lua scrips. Not all of the options need to be exposed here, just those exposed to lua */
49 
50  /// Non-empty if --bunzip2 was given on the command line. Uncompresses a .bz2 file and exits.
51  boost::optional<std::string> bunzip2;
52  /// Non-empty if --bzip2 was given on the command line. Compresses a file to .bz2 and exits.
53  boost::optional<std::string> bzip2;
54  /// Non-empty if --campaign was given on the command line. ID of the campaign we want to start.
55  boost::optional<std::string> campaign;
56  /// Non-empty if --campaign-difficulty was given on the command line. Numerical difficulty of the campaign to be played. Dependent on --campaign.
57  boost::optional<int> campaign_difficulty;
58  /// Non-empty if --campaign-scenario was given on the command line. Chooses starting scenario in the campaign to be played. Dependent on --campaign.
59  boost::optional<std::string> campaign_scenario;
60  /// True if --clock was given on the command line. Enables
61  bool clock;
62  /// Non-empty if --core was given on the command line. Chooses the core to be loaded.
63  boost::optional<std::string> core_id;
64  /// True if --data-path was given on the command line. Prints path to data directory and exits.
65  bool data_path;
66  /// Non-empty if --data-dir was given on the command line. Sets the config dir to the specified one.
67  boost::optional<std::string> data_dir;
68  /// True if --debug was given on the command line. Enables debug mode.
69  bool debug;
70  /// True if --debug-lua was given in the commandline. Enables some Lua debugging mechanisms.
71  bool debug_lua;
72 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
73  /// Non-empty if --debug-dot-domain was given on the command line.
74  boost::optional<std::string> debug_dot_domain;
75  /// Non-empty if --debug-dot-level was given on the command line.
76  boost::optional<std::string> debug_dot_level;
77 #endif
78  /// Non-empty if --editor was given on the command line. Goes directly into editor. If string is longer than 0, it contains path to the file to edit.
79  boost::optional<std::string> editor;
80  /// True if --fps was given on the command line. Shows number of fps.
81  bool fps;
82  /// True if --fullscreen was given on the command line. Starts Wesnoth in fullscreen mode.
83  bool fullscreen;
84  /// Non-empty if --gunzip was given on the command line. Uncompresses a .gz file and exits.
85  boost::optional<std::string> gunzip;
86  /// Non-empty if --gzip was given on the command line. Compresses a file to .gz and exits.
87  boost::optional<std::string> gzip;
88  /// True if --help was given on the command line. Prints help and exits.
89  bool help;
90  /// Non-empty if --language was given on the command line. Sets the language for this session.
91  boost::optional<std::string> language;
92  /// Contains parsed arguments of --log-* (e.g. --log-debug).
93  /// Vector of pairs (severity, log domain).
94  boost::optional<std::vector<boost::tuple<int, std::string> > > log;
95  /// Non-empty if --log-strict was given
96  boost::optional<int> log_strict_level;
97  /// Non-empty if --load was given on the command line. Savegame specified to load after start.
98  boost::optional<std::string> load;
99  /// Non-empty if --logdomains was given on the command line. Prints possible logdomains filtered by given string and exits.
100  boost::optional<std::string> logdomains;
101  /// True if --log-precise was given on the command line. Shows timestamps in log with more precision.
103  /// True if --multiplayer was given on the command line. Goes directly into multiplayer mode.
105  /// Non-empty if --ai-config was given on the command line. Vector of pairs (side number, value). Dependent on --multiplayer.
106  boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_ai_config;
107  /// Non-empty if --algorithm was given on the command line. Vector of pairs (side number, value). Dependent on --multiplayer.
108  boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_algorithm;
109  /// Non-empty if --controller was given on the command line. Vector of pairs (side number, controller). Dependent on --multiplayer.
110  boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_controller;
111  /// Non-empty if --era was given on the command line. Dependent on --multiplayer.
112  boost::optional<std::string> multiplayer_era;
113  /// True if --exit-at-and was given on the command line. Dependent on --multiplayer.
115  /// True if --ignore-map-settings was given at the command line. Do not use map settings.
117  /// Non-empty if --label was given on the command line. Dependent on --multiplayer.
118  boost::optional<std::string> multiplayer_label;
119  /// Non-empty if --parm was given on the command line. Vector of pairs (side number, parm name, parm value). Dependent on --multiplayer.
120  boost::optional<std::vector<boost::tuple<unsigned int, std::string, std::string> > > multiplayer_parm;
121  /// Repeats specified by --multiplayer-repeat option. Repeats a multiplayer game after it is finished. Dependent on --multiplayer.
122  boost::optional<unsigned int> multiplayer_repeat;
123  /// Non-empty if --scenario was given on the command line. Dependent on --multiplayer.
124  boost::optional<std::string> multiplayer_scenario;
125  /// Non-empty if --side was given on the command line. Vector of pairs (side number, faction id). Dependent on --multiplayer.
126  boost::optional<std::vector<boost::tuple<unsigned int, std::string> > > multiplayer_side;
127  /// Non-empty if --turns was given on the command line. Dependent on --multiplayer.
128  boost::optional<std::string> multiplayer_turns;
129  /// Max FPS specified by --max-fps option.
130  boost::optional<int> max_fps;
131  /// True if --noaddons was given on the command line. Disables the loading of all add-ons.
132  bool noaddons;
133  /// True if --nocache was given on the command line. Disables cache usage.
134  bool nocache;
135  /// True if --nodelay was given on the command line.
136  bool nodelay;
137  /// True if --nogui was given on the command line. Disables GUI.
138  bool nogui;
139  /// True if --nomusic was given on the command line. Disables music.
140  bool nomusic;
141  /// True if --nosound was given on the command line. Disables sound.
142  bool nosound;
143  /// True if --new-widgets was given on the command line. Hidden option to enable the new widget toolkit.
145  /// True if --path was given on the command line. Prints the path to data directory and exits.
146  bool path;
147  /// True if --preprocess was given on the command line. Starts Wesnoth in preprocessor-only mode.
149  /// Defines that were given to the --preprocess option.
150  boost::optional<std::vector<std::string> > preprocess_defines;
151  /// Non-empty if --preprocess-input-macros was given on the command line. Specifies a file that contains [preproc_define]s to be included before preprocessing. Dependant on --preprocess.
152  boost::optional<std::string> preprocess_input_macros;
153  /// Non-empty if --preprocess-output-macros was given on the command line. Outputs all preprocessed macros to the specified file. Dependant on --preprocess.
154  boost::optional<std::string> preprocess_output_macros;
155  /// Path to parse that was given to the --preprocess option.
156  boost::optional<std::string> preprocess_path;
157  /// Target (output) path that was given to the --preprocess option.
158  boost::optional<std::string> preprocess_target;
159  /// Pair of AxB values specified after --resolution. Changes Wesnoth resolution.
160  boost::optional<boost::tuple<int,int> > resolution;
161  /// RNG seed specified by --rng-seed option. Initializes RNG with given seed.
162  boost::optional<unsigned int> rng_seed;
163  /// Non-empty if --server was given on the command line. Connects Wesnoth to specified server. If no server was specified afterwards, contains an empty string.
164  boost::optional<std::string> server;
165  /// Non-empty if --username was given on the command line. Forces Wesnoth to use this network username.
166  boost::optional<std::string> username;
167  /// Non-empty if --password was given on the command line. Forces Wesnoth to use this network password.
168  boost::optional<std::string> password;
169  /// Image path to render. First parameter after --render-image
170  boost::optional<std::string> render_image;
171  /// Output file to put rendered image path in. Optional second parameter after --render-image
172  boost::optional<std::string> render_image_dst;
173  /// True if --screenshot was given on the command line. Starts Wesnoth in screenshot mode.
175  /// Map file to make a screenshot of. First parameter given after --screenshot.
176  boost::optional<std::string> screenshot_map_file;
177  /// Output file to put screenshot in. Second parameter given after --screenshot.
178  boost::optional<std::string> screenshot_output_file;
179  /// File to load lua script from.
180  boost::optional<std::string> script_file;
181  /// File to load a lua plugin (similar to a script) from. Experimental / may replace script.
182  boost::optional<std::string> plugin_file;
183  /// Whether to load the "package" package for the scripting environment. (This allows to load arbitrary lua packages, and gives untrusted lua the same permissions as wesnoth executable)
185  /// True if --strict-validation was given on the command line. Makes Wesnoth trust validation errors as fatal WML errors and create WML exception, if so.
187  /// Non-empty if --test was given on the command line. Goes directly into test mode, into a scenario, if specified.
188  boost::optional<std::string> test;
189  /// Non-empty if --unit was given on the command line. Goes directly into unit test mode, into a scenario, if specified.
190  boost::optional<std::string> unit_test;
191  /// True if --unit is used and --showgui is not present.
193  /// Non-empty if --timeout was given on the command line. Dependent on --unit.
194  boost::optional<unsigned int> timeout;
195  /// True if --noreplaycheck was given on the comand line. Dependent on --unit.
197  /// True if --mp-test was given on the command line.
198  bool mptest;
199  /// True if --userconfig-path was given on the command line. Prints path to user config directory and exits.
201  /// Non-empty if --userconfig-dir was given on the command line. Sets the user config dir to the specified one.
202  boost::optional<std::string> userconfig_dir;
203  /// True if --userdata-path was given on the command line. Prints path to user data directory and exits.
205  /// Non-empty if --userdata-dir was given on the command line. Sets the user data dir to the specified one.
206  boost::optional<std::string> userdata_dir;
207  /// True if --validcache was given on the command line. Makes Wesnoth assume the cache is valid.
209  /// True if --version was given on the command line. Prints version and exits.
210  bool version;
211  /// True if --windowed was given on the command line. Starts Wesnoth in windowed mode.
212  bool windowed;
213  /// True if --with-replay was given on the command line. Shows replay of the loaded file.
215 private:
216  void parse_log_domains_(const std::string &domains_string, const int severity);
218  void parse_resolution_ (const std::string &resolution_string);
219  /// A helper function splitting vector of strings of format unsigned int:string to vector of tuples (unsigned int,string)
220  std::vector<boost::tuple<unsigned int,std::string> > parse_to_uint_string_tuples_(const std::vector<std::string> &strings, char separator = ':');
221  /// A helper function splitting vector of strings of format unsigned int:string:string to vector of tuples (unsigned int,string,string)
222  std::vector<boost::tuple<unsigned int,std::string,std::string> > parse_to_uint_string_string_tuples_(const std::vector<std::string> &strings, char separator = ':');
223  std::vector<std::string> args_;
225  boost::program_options::options_description all_;
226  boost::program_options::options_description visible_;
227  boost::program_options::options_description hidden_;
228 };
229 
230 #endif
boost::optional< std::string > core_id
Non-empty if –core was given on the command line. Chooses the core to be loaded. ...
bool log_precise_timestamps
True if –log-precise was given on the command line. Shows timestamps in log with more precision...
boost::optional< std::string > script_file
File to load lua script from.
std::vector< std::string > args_
bool mptest
True if –mp-test was given on the command line.
boost::program_options::options_description all_
boost::optional< std::vector< boost::tuple< unsigned int, std::string, std::string > > > multiplayer_parm
Non-empty if –parm was given on the command line. Vector of pairs (side number, parm name...
bool nogui
True if –nogui was given on the command line. Disables GUI.
boost::optional< std::string > multiplayer_turns
Non-empty if –turns was given on the command line. Dependent on –multiplayer.
bool script_unsafe_mode
Whether to load the "package" package for the scripting environment. (This allows to load arbitrary l...
boost::optional< std::vector< boost::tuple< unsigned int, std::string > > > multiplayer_algorithm
Non-empty if –algorithm was given on the command line. Vector of pairs (side number, value). Dependent on –multiplayer.
boost::optional< std::string > bzip2
Non-empty if –bzip2 was given on the command line. Compresses a file to .bz2 and exits...
commandline_options(const std::vector< std::string > &args)
boost::program_options::options_description hidden_
static l_noret error(LoadState *S, const char *why)
Definition: lundump.cpp:29
bool noaddons
True if –noaddons was given on the command line. Disables the loading of all add-ons.
void parse_log_domains_(const std::string &domains_string, const int severity)
bool userdata_path
True if –userdata-path was given on the command line. Prints path to user data directory and exits...
boost::optional< std::string > multiplayer_scenario
Non-empty if –scenario was given on the command line. Dependent on –multiplayer.
bool multiplayer_ignore_map_settings
True if –ignore-map-settings was given at the command line. Do not use map settings.
boost::optional< std::string > username
Non-empty if –username was given on the command line. Forces Wesnoth to use this network username...
boost::optional< std::string > gunzip
Non-empty if –gunzip was given on the command line. Uncompresses a .gz file and exits.
boost::optional< std::string > campaign_scenario
Non-empty if –campaign-scenario was given on the command line. Chooses starting scenario in the camp...
boost::optional< int > log_strict_level
Non-empty if –log-strict was given.
boost::optional< int > max_fps
Max FPS specified by –max-fps option.
boost::optional< unsigned int > rng_seed
RNG seed specified by –rng-seed option. Initializes RNG with given seed.
bool fps
True if –fps was given on the command line. Shows number of fps.
boost::optional< std::string > data_dir
Non-empty if –data-dir was given on the command line. Sets the config dir to the specified one...
boost::optional< std::vector< boost::tuple< int, std::string > > > log
Contains parsed arguments of –log-* (e.g.
bool noreplaycheck
True if –noreplaycheck was given on the comand line. Dependent on –unit.
std::vector< boost::tuple< unsigned int, std::string > > parse_to_uint_string_tuples_(const std::vector< std::string > &strings, char separator= ':')
A helper function splitting vector of strings of format unsigned int:string to vector of tuples (unsi...
boost::optional< std::string > multiplayer_era
Non-empty if –era was given on the command line. Dependent on –multiplayer.
void parse_resolution_(const std::string &resolution_string)
bad_commandline_tuple(const std::string &str, const std::string &expected_format)
boost::optional< std::string > plugin_file
File to load a lua plugin (similar to a script) from. Experimental / may replace script.
boost::optional< std::string > multiplayer_label
Non-empty if –label was given on the command line. Dependent on –multiplayer.
boost::optional< unsigned int > timeout
Non-empty if –timeout was given on the command line. Dependent on –unit.
boost::optional< std::string > load
Non-empty if –load was given on the command line. Savegame specified to load after start...
bool preprocess
True if –preprocess was given on the command line. Starts Wesnoth in preprocessor-only mode...
bool with_replay
True if –with-replay was given on the command line. Shows replay of the loaded file.
bool headless_unit_test
True if –unit is used and –showgui is not present.
boost::optional< std::string > userconfig_dir
Non-empty if –userconfig-dir was given on the command line. Sets the user config dir to the specifie...
boost::optional< std::vector< boost::tuple< unsigned int, std::string > > > multiplayer_controller
Non-empty if –controller was given on the command line. Vector of pairs (side number, controller). Dependent on –multiplayer.
bool nodelay
True if –nodelay was given on the command line.
boost::optional< std::string > logdomains
Non-empty if –logdomains was given on the command line. Prints possible logdomains filtered by given...
bool windowed
True if –windowed was given on the command line. Starts Wesnoth in windowed mode.
boost::optional< std::string > editor
Non-empty if –editor was given on the command line. Goes directly into editor. If string is longer t...
boost::optional< std::string > userdata_dir
Non-empty if –userdata-dir was given on the command line. Sets the user data dir to the specified on...
boost::optional< std::string > gzip
Non-empty if –gzip was given on the command line. Compresses a file to .gz and exits.
std::pair< int, int > resolution()
boost::optional< std::string > preprocess_output_macros
Non-empty if –preprocess-output-macros was given on the command line. Outputs all preprocessed macro...
boost::optional< std::string > test
Non-empty if –test was given on the command line. Goes directly into test mode, into a scenario...
bool multiplayer
True if –multiplayer was given on the command line. Goes directly into multiplayer mode...
bool clock
True if –clock was given on the command line. Enables.
bool userconfig_path
True if –userconfig-path was given on the command line. Prints path to user config directory and exi...
GLenum severity
Definition: glew.h:2497
bool path
True if –path was given on the command line. Prints the path to data directory and exits...
boost::optional< std::string > render_image
Image path to render. First parameter after –render-image.
boost::optional< int > campaign_difficulty
Non-empty if –campaign-difficulty was given on the command line. Numerical difficulty of the campaig...
bool nomusic
True if –nomusic was given on the command line. Disables music.
GLsizei const GLchar ** strings
Definition: glew.h:1812
boost::optional< std::string > password
Non-empty if –password was given on the command line. Forces Wesnoth to use this network password...
boost::optional< std::string > preprocess_target
Target (output) path that was given to the –preprocess option.
bool debug
True if –debug was given on the command line. Enables debug mode.
bool debug_lua
True if –debug-lua was given in the commandline. Enables some Lua debugging mechanisms.
bool nocache
True if –nocache was given on the command line. Disables cache usage.
boost::optional< std::string > screenshot_map_file
Map file to make a screenshot of. First parameter given after –screenshot.
boost::optional< std::string > preprocess_path
Path to parse that was given to the –preprocess option.
bool new_widgets
True if –new-widgets was given on the command line. Hidden option to enable the new widget toolkit...
boost::optional< std::string > bunzip2
Non-empty if –bunzip2 was given on the command line. Uncompresses a .bz2 file and exits...
boost::optional< std::vector< boost::tuple< unsigned int, std::string > > > multiplayer_ai_config
Non-empty if –ai-config was given on the command line. Vector of pairs (side number, value). Dependent on –multiplayer.
boost::optional< std::vector< boost::tuple< unsigned int, std::string > > > multiplayer_side
Non-empty if –side was given on the command line. Vector of pairs (side number, faction id)...
bad_commandline_resolution(const std::string &resolution)
std::vector< boost::tuple< unsigned int, std::string, std::string > > parse_to_uint_string_string_tuples_(const std::vector< std::string > &strings, char separator= ':')
A helper function splitting vector of strings of format unsigned int:string:string to vector of tuple...
boost::optional< std::string > render_image_dst
Output file to put rendered image path in. Optional second parameter after –render-image.
void parse_log_strictness(const std::string &severity)
bool data_path
True if –data-path was given on the command line. Prints path to data directory and exits...
bool screenshot
True if –screenshot was given on the command line. Starts Wesnoth in screenshot mode.
boost::optional< std::string > unit_test
Non-empty if –unit was given on the command line. Goes directly into unit test mode, into a scenario, if specified.
boost::optional< unsigned int > multiplayer_repeat
Repeats specified by –multiplayer-repeat option. Repeats a multiplayer game after it is finished...
bool version
True if –version was given on the command line. Prints version and exits.
boost::optional< std::string > screenshot_output_file
Output file to put screenshot in. Second parameter given after –screenshot.
bool fullscreen
True if –fullscreen was given on the command line. Starts Wesnoth in fullscreen mode.
bool validcache
True if –validcache was given on the command line. Makes Wesnoth assume the cache is valid...
bool strict_validation
True if –strict-validation was given on the command line. Makes Wesnoth trust validation errors as f...
boost::optional< std::vector< std::string > > preprocess_defines
Defines that were given to the –preprocess option.
boost::optional< std::string > language
Non-empty if –language was given on the command line. Sets the language for this session...
bool nosound
True if –nosound was given on the command line. Disables sound.
boost::optional< std::string > preprocess_input_macros
Non-empty if –preprocess-input-macros was given on the command line. Specifies a file that contains ...
boost::program_options::options_description visible_
friend std::ostream & operator<<(std::ostream &os, const commandline_options &cmdline_opts)
To be used for printing help to the commandline.
bool multiplayer_exit_at_end
True if –exit-at-and was given on the command line. Dependent on –multiplayer.
boost::optional< std::string > campaign
Non-empty if –campaign was given on the command line. ID of the campaign we want to start...
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool help
True if –help was given on the command line. Prints help and exits.
boost::optional< std::string > server
Non-empty if –server was given on the command line. Connects Wesnoth to specified server...
boost::optional< boost::tuple< int, int > > resolution
Pair of AxB values specified after –resolution. Changes Wesnoth resolution.