Skip to content

Commit e3738c2

Browse files
Markus Mattesrubenwardy
Markus Mattes
authored andcommittedJun 21, 2019
Fix handling of --color and --worldlist command line arguments
They verify the provided value and error if a wrong value got provided command line description for color was differnt on win32 but code did not handle any differenc extended the command line description for world and worldname that it is clear that they only start a local game if used with --go Fixes #7875
1 parent 7eb110d commit e3738c2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed
 

Diff for: ‎src/main.cpp

+20-17
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void print_modified_quicktune_values();
7979

8080
static void list_game_ids();
8181
static void list_worlds(bool print_name, bool print_path);
82-
static void setup_log_params(const Settings &cmd_args);
82+
static bool setup_log_params(const Settings &cmd_args);
8383
static bool create_userdata_path();
8484
static bool init_common(const Settings &cmd_args, int argc, char *argv[]);
8585
static void startup_message();
@@ -135,7 +135,8 @@ int main(int argc, char *argv[])
135135
return 0;
136136
}
137137

138-
setup_log_params(cmd_args);
138+
if (!setup_log_params(cmd_args))
139+
return 1;
139140

140141
porting::signal_handler_init();
141142

@@ -166,8 +167,12 @@ int main(int argc, char *argv[])
166167
list_worlds(true, false);
167168
} else if (cmd_args.get("worldlist") == "path") {
168169
list_worlds(false, true);
169-
} else {
170+
} else if (cmd_args.get("worldlist") == "both") {
170171
list_worlds(true, true);
172+
} else {
173+
errorstream << "Invalid --worldlist value: "
174+
<< cmd_args.get("worldlist") << std::endl;
175+
return 1;
171176
}
172177
return 0;
173178
}
@@ -258,23 +263,17 @@ static void set_allowed_options(OptionList *allowed_options)
258263
allowed_options->insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
259264
_("Same as --world (deprecated)"))));
260265
allowed_options->insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
261-
_("Set world path (implies local game)"))));
266+
_("Set world path (implies local game if used with option --go)"))));
262267
allowed_options->insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
263-
_("Set world by name (implies local game)"))));
268+
_("Set world by name (implies local game if used with option --go)"))));
264269
allowed_options->insert(std::make_pair("worldlist", ValueSpec(VALUETYPE_STRING,
265-
_("Get list of worlds (implies local game) ('path' lists paths, "
270+
_("Get list of worlds ('path' lists paths, "
266271
"'name' lists names, 'both' lists both)"))));
267272
allowed_options->insert(std::make_pair("quiet", ValueSpec(VALUETYPE_FLAG,
268273
_("Print to console errors only"))));
269-
#if !defined(_WIN32)
270274
allowed_options->insert(std::make_pair("color", ValueSpec(VALUETYPE_STRING,
271275
_("Coloured logs ('always', 'never' or 'auto'), defaults to 'auto'"
272276
))));
273-
#else
274-
allowed_options->insert(std::make_pair("color", ValueSpec(VALUETYPE_STRING,
275-
_("Coloured logs ('always' or 'never'), defaults to 'never'"
276-
))));
277-
#endif
278277
allowed_options->insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
279278
_("Print more information to console"))));
280279
allowed_options->insert(std::make_pair("verbose", ValueSpec(VALUETYPE_FLAG,
@@ -398,7 +397,7 @@ static void print_modified_quicktune_values()
398397
}
399398
}
400399

401-
static void setup_log_params(const Settings &cmd_args)
400+
static bool setup_log_params(const Settings &cmd_args)
402401
{
403402
// Quiet mode, print errors only
404403
if (cmd_args.getFlag("quiet")) {
@@ -418,14 +417,16 @@ static void setup_log_params(const Settings &cmd_args)
418417
#endif
419418
}
420419
if (color_mode != "") {
421-
if (color_mode == "auto")
420+
if (color_mode == "auto") {
422421
Logger::color_mode = LOG_COLOR_AUTO;
423-
else if (color_mode == "always")
422+
} else if (color_mode == "always") {
424423
Logger::color_mode = LOG_COLOR_ALWAYS;
425-
else if (color_mode == "never")
424+
} else if (color_mode == "never") {
426425
Logger::color_mode = LOG_COLOR_NEVER;
427-
else
426+
} else {
428427
errorstream << "Invalid color mode: " << color_mode << std::endl;
428+
return false;
429+
}
429430
}
430431

431432
// If trace is enabled, enable logging of certain things
@@ -444,6 +445,8 @@ static void setup_log_params(const Settings &cmd_args)
444445
// In certain cases, output verbose level on stderr
445446
if (cmd_args.getFlag("verbose") || cmd_args.getFlag("trace"))
446447
g_logger.addOutput(&stderr_output, LL_VERBOSE);
448+
449+
return true;
447450
}
448451

449452
static bool create_userdata_path()

0 commit comments

Comments
 (0)
Please sign in to comment.