The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
commandline_options.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2011 - 2025
3 by Lukasz Dobrogowski <lukasz.dobrogowski@gmail.com>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include "log.hpp" // for logger, set_strict_severity, etc
19
21
22#include <boost/program_options/options_description.hpp>
23#include <iosfwd> // for ostream
24#include <string> // for string
25#include <tuple>
26#include <vector> // for vector
27
28class bad_commandline_resolution : public boost::program_options::error
29{
30public:
31 bad_commandline_resolution(const std::string& resolution);
32};
33
34class bad_commandline_tuple : public boost::program_options::error
35{
36public:
37 bad_commandline_tuple(const std::string& str,
38 const std::string& expected_format);
39};
40
41class config;
42
44{
45 /** To be used for printing help to the commandline. */
46 friend std::ostream& operator<<(std::ostream &os, const commandline_options& cmdline_opts);
47
48public:
49 commandline_options(const std::vector<std::string>& args);
50
51 config to_config() const; /* Used by lua scrips. Not all of the options need to be exposed here, just those exposed to lua */
52
53 /** True if the --validate or any of the --validate-* options are given. */
54 bool any_validation_option() const;
55
56 /** Non-empty if --campaign was given on the command line. ID of the campaign we want to start. */
57 utils::optional<std::string> campaign;
58 /** Non-empty if --campaign-difficulty was given on the command line. Numerical difficulty of the campaign to be played. Dependent on --campaign. */
59 utils::optional<int> campaign_difficulty;
60 /** Non-empty if --campaign-scenario was given on the command line. Chooses starting scenario in the campaign to be played. Dependent on --campaign. */
61 utils::optional<std::string> campaign_scenario;
62 /** True if --skip-story was given on the command line. Skips [story] and [message]s through the end of the "start" event. Dependent on --campaign. */
64 /** True if --clock was given on the command line. Enables */
65 bool clock;
66 /** Non-empty if --core was given on the command line. Chooses the core to be loaded. */
67 utils::optional<std::string> core_id;
68 /** True if --data-path was given on the command line. Prints path to data directory and exits. */
70 /** Non-empty if --data-dir was given on the command line. Sets the config dir to the specified one. */
71 utils::optional<std::string> data_dir;
72 /** True if --debug was given on the command line. Enables debug mode. */
73 bool debug;
74 /** True if --debug-lua was given in the commandline. Enables some Lua debugging mechanisms. */
76 /** True if --strict-lua was given in the commandline. Disallows use of deprecated APIs. */
78 /**
79 * True if --allow-insecure was given in the commandline.
80 * Allows sending a plaintext password over an unencrypted connection.
81 * Should only ever be used for local testing.
82 */
85#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
86 /** Non-empty if --debug-dot-domain was given on the command line. */
87 utils::optional<std::string> debug_dot_domain;
88 /** Non-empty if --debug-dot-level was given on the command line. */
89 utils::optional<std::string> debug_dot_level;
90#endif
91 /** 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. */
92 utils::optional<std::string> editor;
93 /** True if --fps was given on the command line. Shows number of fps. */
94 bool fps;
95 /** True if --fullscreen was given on the command line. Starts Wesnoth in fullscreen mode. */
97 /** True if --help was given on the command line. Prints help and exits. */
98 bool help;
99 /** Non-empty if --language was given on the command line. Sets the language for this session. */
100 utils::optional<std::string> language;
101 /**
102 * Contains parsed arguments of --log-* (e.g. --log-debug).
103 * Vector of pairs (severity, log domain).
104 */
105 utils::optional<std::vector<std::pair<lg::severity, std::string>>> log;
106 /** Non-empty if --log-strict was given */
107 utils::optional<int> log_strict_level;
108 /** Non-empty if --load was given on the command line. Savegame specified to load after start. */
109 utils::optional<std::string> load;
110 /** Non-empty if --logdomains was given on the command line. Prints possible logdomains filtered by given string and exits. */
111 utils::optional<std::string> logdomains;
112 /** True if --log-precise was given on the command line. Shows timestamps in log with more precision. */
114 /** True if --multiplayer was given on the command line. Goes directly into multiplayer mode. */
116 /** Non-empty if --ai-config was given on the command line. Vector of pairs (side number, value). Dependent on --multiplayer. */
117 utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_ai_config;
118 /** Non-empty if --algorithm was given on the command line. Vector of pairs (side number, value). Dependent on --multiplayer. */
119 utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_algorithm;
120 /** Non-empty if --controller was given on the command line. Vector of pairs (side number, controller). Dependent on --multiplayer. */
121 utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_controller;
122 /** Non-empty if --era was given on the command line. Dependent on --multiplayer. */
123 utils::optional<std::string> multiplayer_era;
124 /** True if --exit-at-and was given on the command line. Dependent on --multiplayer. */
126 /** True if --ignore-map-settings was given at the command line. Do not use map settings. */
128 /** Non-empty if --label was given on the command line. Dependent on --multiplayer. */
129 utils::optional<std::string> multiplayer_label;
130 /** Non-empty if --parm was given on the command line. Vector of pairs (side number, parm name, parm value). Dependent on --multiplayer. */
131 utils::optional<std::vector<std::tuple<unsigned int, std::string, std::string>>> multiplayer_parm;
132 /** Repeats specified by --multiplayer-repeat option. Repeats a multiplayer game after it is finished. Dependent on --multiplayer. */
133 utils::optional<unsigned int> multiplayer_repeat;
134 /** Non-empty if --scenario was given on the command line. Dependent on --multiplayer. */
135 utils::optional<std::string> multiplayer_scenario;
136 /** Non-empty if --side was given on the command line. Vector of pairs (side number, faction id). Dependent on --multiplayer. */
137 utils::optional<std::vector<std::pair<unsigned int, std::string>>> multiplayer_side;
138 /** Non-empty if --turns was given on the command line. Dependent on --multiplayer. */
139 utils::optional<std::string> multiplayer_turns;
140 /** Max FPS specified by --max-fps option. */
141 utils::optional<int> max_fps;
142 /** True if --noaddons was given on the command line. Disables the loading of all add-ons. */
144 /** True if --nocache was given on the command line. Disables cache usage. */
146 /** True if --nogui was given on the command line. Disables GUI. */
147 bool nogui;
148 /** True if --nobanner was given on the command line. Disables startup banner. */
150 /** True if --nomusic was given on the command line. Disables music. */
152 /** True if --no-simd was given on the command line. Disables SIMD hardware acceleration. */
154 /** True if --nosound was given on the command line. Disables sound. */
156 /** True if --new-widgets was given on the command line. Hidden option to enable the new widget toolkit. */
158 /** True if --preprocess was given on the command line. Starts Wesnoth in preprocessor-only mode. */
160 /** Defines that were given to the --preprocess option. */
161 utils::optional<std::vector<std::string>> preprocess_defines;
162 /** 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. Dependent on --preprocess. */
163 utils::optional<std::string> preprocess_input_macros;
164 /** Non-empty if --preprocess-output-macros was given on the command line. Outputs all preprocessed macros to the specified file. Dependent on --preprocess. */
165 utils::optional<std::string> preprocess_output_macros;
166 /** Path to parse that was given to the --preprocess option. */
167 utils::optional<std::string> preprocess_path;
168 /** Target (output) path that was given to the --preprocess option. */
169 utils::optional<std::string> preprocess_target;
170 /** String to preprocess */
171 utils::optional<std::string> preprocess_source_string;
172 /** Pair of AxB values specified after --resolution. Changes Wesnoth resolution. */
173 utils::optional<std::pair<int,int>> resolution;
174 /** RNG seed specified by --rng-seed option. Initializes RNG with given seed. */
175 utils::optional<unsigned int> rng_seed;
176 /** 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. */
177 utils::optional<std::string> server;
178 /** Non-empty if --username was given on the command line. Forces Wesnoth to use this network username. */
179 utils::optional<std::string> username;
180 /** Non-empty if --password was given on the command line. Forces Wesnoth to use this network password. */
181 utils::optional<std::string> password;
182 /** Image path to render. First parameter after --render-image */
183 utils::optional<std::string> render_image;
184 /** Output file to put rendered image path in. Optional second parameter after --render-image */
185 utils::optional<std::string> render_image_dst;
186 /** Path of which to generate a spritesheet */
187 utils::optional<std::string> generate_spritesheet;
188 /** True if --screenshot was given on the command line. Starts Wesnoth in screenshot mode. */
190 /** Map file to make a screenshot of. First parameter given after --screenshot. */
191 utils::optional<std::string> screenshot_map_file;
192 /** Output file to put screenshot in. Second parameter given after --screenshot. */
193 utils::optional<std::string> screenshot_output_file;
194 /** File to load a lua plugin script from. */
195 utils::optional<std::string> plugin_file;
196 /** 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) */
198 /** 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. */
200 /** Non-empty if --test was given on the command line. Goes directly into test mode, into a scenario, if specified. */
201 utils::optional<std::string> test;
202 /** Non-empty if --unit was given on the command line. Goes directly into unit test mode, into a scenario, if specified. */
203 std::vector<std::string> unit_test;
204 /** True if --unit is used and --showgui is not present. */
206 /** True if --noreplaycheck was given on the command line. Dependent on --unit. */
208 /** True if --mp-test was given on the command line. */
209 bool mptest;
210 /** True if --usercache-path was given on the command line. Prints path to cache directory and exits. */
212 /** Non-empty if --usercache-dir was given on the command line. Sets the cache dir to the specified one. */
213 utils::optional<std::string> usercache_dir;
214 /** True if --userdata-path was given on the command line. Prints path to user data directory and exits. */
216 /** Non-empty if --userdata-dir was given on the command line. Sets the user data dir to the specified one. */
217 utils::optional<std::string> userdata_dir;
218 /** True if --validcache was given on the command line. Makes Wesnoth assume the cache is valid. */
220 /** True if --validate-core was given on the command line. Makes Wesnoth validate the core WML. */
222 /** Non-empty if --validate-addon was given on the command line. Makes Wesnoth validate an addon's WML. */
223 utils::optional<std::string> validate_addon;
224 /** Non-empty if --validate-schema was given on the command line. Makes Wesnoth validate a WML schema. */
225 utils::optional<std::string> validate_schema;
226 /** Non-empty if --validate was given on the command line. Makes Wesnoth validate a WML file against a schema. */
227 utils::optional<std::string> validate_wml;
228 /** Non-empty if --use-schema was given on the command line. Specifies the schema for use with --validate. */
229 utils::optional<std::string> validate_with;
230 /** Output filename for WML diff or preprocessing */
231 utils::optional<std::string> output_file;
233 /** Files for diffing or patching */
234 std::string diff_left, diff_right;
235 /** True if --version was given on the command line. Prints version and exits. */
237 /** True if --simple-version was given on the command line. Prints version and nothing else then exits. */
239 /** True if --report was given on the command line. Prints a bug report-style info dump and exits. */
240 bool report;
241 /** True if --windowed was given on the command line. Starts Wesnoth in windowed mode. */
243 /** True if --with-replay was given on the command line. Shows replay of the loaded file. */
245#ifdef _WIN32
246 /** True if --wnoconsole was given on the command line. Prevents logs from being written to the console window if Wesnoth is launched from the command prompt on Windows. */
247 bool no_console;
248#endif
249 /** True if --no-log-sanitize was given on the command line. Prevents removal of OS user from file paths in log files. */
251 /**
252 * True if --log-to-file was given on the command line.
253 * Forces output to be written to a log file. Takes priority over any arguments that implicitly prevent logging to file.
254 */
256 /** True if --no-log-to-file was given on the command line. Results in logs not being redirected to a log file. */
258 /** Non-empty if --all-translations or --translations-over is given on the command line. */
259 utils::optional<unsigned int> translation_percent;
260private:
261 void parse_log_domains_(const std::string &domains_string, const lg::severity severity);
262 void parse_log_strictness (const std::string &severity);
263 void parse_resolution_ (const std::string &resolution_string);
264 /** A helper function splitting vector of strings of format unsigned int:string to vector of tuples (unsigned int,string) */
265 std::vector<std::pair<unsigned int,std::string>> parse_to_uint_string_tuples_(const std::vector<std::string> &strings, char separator = ':');
266 /** A helper function splitting vector of strings of format unsigned int:string:string to vector of tuples (unsigned int,string,string) */
267 std::vector<std::tuple<unsigned int,std::string,std::string>> parse_to_uint_string_string_tuples_(const std::vector<std::string> &strings, char separator = ':');
268 std::vector<std::string> args_;
269 std::string args0_;
270 boost::program_options::options_description all_;
271 boost::program_options::options_description visible_;
272 boost::program_options::options_description hidden_;
273};
bool nogui
True if –nogui was given on the command line.
utils::optional< std::vector< std::pair< unsigned int, std::string > > > multiplayer_side
Non-empty if –side was given on the command line.
bool print_userdata_path
True if –userdata-path was given on the command line.
utils::optional< std::pair< int, int > > resolution
Pair of AxB values specified after –resolution.
utils::optional< std::string > validate_wml
Non-empty if –validate was given on the command line.
bool simple_version
True if –simple-version was given on the command line.
bool report
True if –report was given on the command line.
boost::program_options::options_description hidden_
bool headless_unit_test
True if –unit is used and –showgui is not present.
utils::optional< std::string > screenshot_map_file
Map file to make a screenshot of.
utils::optional< std::string > multiplayer_scenario
Non-empty if –scenario was given on the command line.
utils::optional< std::string > test
Non-empty if –test was given on the command line.
bool no_log_sanitize
True if –no-log-sanitize was given on the command line.
bool windowed
True if –windowed was given on the command line.
bool strict_lua
True if –strict-lua was given in the commandline.
utils::optional< std::string > language
Non-empty if –language was given on the command line.
bool print_usercache_path
True if –usercache-path was given on the command line.
std::vector< std::pair< 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...
utils::optional< std::vector< std::string > > preprocess_defines
Defines that were given to the –preprocess option.
bool noreplaycheck
True if –noreplaycheck was given on the command line.
utils::optional< std::string > screenshot_output_file
Output file to put screenshot in.
void parse_log_domains_(const std::string &domains_string, const lg::severity severity)
utils::optional< std::string > usercache_dir
Non-empty if –usercache-dir was given on the command line.
bool no_simd
True if –no-simd was given on the command line.
utils::optional< int > max_fps
Max FPS specified by –max-fps option.
utils::optional< std::string > core_id
Non-empty if –core was given on the command line.
bool multiplayer_exit_at_end
True if –exit-at-and was given on the command line.
utils::optional< std::string > validate_addon
Non-empty if –validate-addon was given on the command line.
utils::optional< int > campaign_difficulty
Non-empty if –campaign-difficulty was given on the command line.
utils::optional< unsigned int > multiplayer_repeat
Repeats specified by –multiplayer-repeat option.
utils::optional< std::string > validate_schema
Non-empty if –validate-schema was given on the command line.
bool debug
True if –debug was given on the command line.
bool mptest
True if –mp-test was given on the command line.
void parse_log_strictness(const std::string &severity)
bool nosound
True if –nosound was given on the command line.
bool multiplayer
True if –multiplayer was given on the command line.
utils::optional< std::string > server
Non-empty if –server was given on the command line.
bool script_unsafe_mode
Whether to load the "package" package for the scripting environment.
utils::optional< std::string > userdata_dir
Non-empty if –userdata-dir was given on the command line.
std::vector< std::string > args_
utils::optional< unsigned int > translation_percent
Non-empty if –all-translations or –translations-over is given on the command line.
utils::optional< std::string > plugin_file
File to load a lua plugin script from.
bool nobanner
True if –nobanner was given on the command line.
utils::optional< std::vector< std::pair< lg::severity, std::string > > > log
Contains parsed arguments of –log-* (e.g.
bool validcache
True if –validcache was given on the command line.
utils::optional< std::string > generate_spritesheet
Path of which to generate a spritesheet.
std::vector< std::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...
bool nomusic
True if –nomusic was given on the command line.
bool clock
True if –clock was given on the command line.
utils::optional< std::string > render_image_dst
Output file to put rendered image path in.
utils::optional< std::string > render_image
Image path to render.
boost::program_options::options_description visible_
utils::optional< std::string > campaign
Non-empty if –campaign was given on the command line.
utils::optional< std::string > logdomains
Non-empty if –logdomains was given on the command line.
bool new_widgets
True if –new-widgets was given on the command line.
utils::optional< std::string > preprocess_input_macros
Non-empty if –preprocess-input-macros was given on the command line.
bool preprocess
True if –preprocess was given on the command line.
utils::optional< unsigned int > rng_seed
RNG seed specified by –rng-seed option.
std::string diff_left
Files for diffing or patching.
utils::optional< std::vector< std::pair< unsigned int, std::string > > > multiplayer_ai_config
Non-empty if –ai-config was given on the command line.
bool version
True if –version was given on the command line.
utils::optional< std::string > multiplayer_label
Non-empty if –label was given on the command line.
bool allow_insecure
True if –allow-insecure was given in the commandline.
void parse_resolution_(const std::string &resolution_string)
utils::optional< std::string > multiplayer_era
Non-empty if –era was given on the command line.
utils::optional< std::string > validate_with
Non-empty if –use-schema was given on the command line.
bool noaddons
True if –noaddons was given on the command line.
bool fps
True if –fps was given on the command line.
utils::optional< std::string > output_file
Output filename for WML diff or preprocessing.
utils::optional< int > log_strict_level
Non-empty if –log-strict was given.
utils::optional< std::string > multiplayer_turns
Non-empty if –turns was given on the command line.
utils::optional< std::string > data_dir
Non-empty if –data-dir was given on the command line.
utils::optional< std::string > username
Non-empty if –username was given on the command line.
utils::optional< std::string > preprocess_target
Target (output) path that was given to the –preprocess option.
bool campaign_skip_story
True if –skip-story was given on the command line.
bool with_replay
True if –with-replay was given on the command line.
bool screenshot
True if –screenshot was given on the command line.
bool log_to_file
True if –log-to-file was given on the command line.
bool debug_lua
True if –debug-lua was given in the commandline.
std::vector< std::string > unit_test
Non-empty if –unit was given on the command line.
bool log_precise_timestamps
True if –log-precise was given on the command line.
utils::optional< std::string > preprocess_source_string
String to preprocess.
bool no_log_to_file
True if –no-log-to-file was given on the command line.
bool multiplayer_ignore_map_settings
True if –ignore-map-settings was given at the command line.
utils::optional< std::string > editor
Non-empty if –editor was given on the command line.
utils::optional< std::string > password
Non-empty if –password was given on the command line.
utils::optional< std::string > preprocess_output_macros
Non-empty if –preprocess-output-macros was given on the command line.
bool fullscreen
True if –fullscreen was given on the command line.
bool any_validation_option() const
True if the –validate or any of the –validate-* options are given.
utils::optional< std::vector< std::pair< unsigned int, std::string > > > multiplayer_controller
Non-empty if –controller was given on the command line.
bool strict_validation
True if –strict-validation was given on the command line.
bool validate_core
True if –validate-core was given on the command line.
utils::optional< std::vector< std::pair< unsigned int, std::string > > > multiplayer_algorithm
Non-empty if –algorithm was given on the command line.
utils::optional< std::string > preprocess_path
Path to parse that was given to the –preprocess option.
bool help
True if –help was given on the command line.
friend std::ostream & operator<<(std::ostream &os, const commandline_options &cmdline_opts)
To be used for printing help to the commandline.
bool nocache
True if –nocache was given on the command line.
utils::optional< std::vector< std::tuple< unsigned int, std::string, std::string > > > multiplayer_parm
Non-empty if –parm was given on the command line.
boost::program_options::options_description all_
bool print_data_path
True if –data-path was given on the command line.
utils::optional< std::string > campaign_scenario
Non-empty if –campaign-scenario was given on the command line.
utils::optional< std::string > load
Non-empty if –load was given on the command line.
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
Standard logging facilities (interface).
severity
Definition log.hpp:82