Skip to content

Commit 929792e

Browse files
BitOfAByteSmallJoker
authored andcommittedMar 4, 2018
Allow for getting world name and path separately on the command line (#6555)
Change to --worldlist instead of --world list. Gets rid of --worldpath parameter added as part of this pull request, instead moving the listing function to a command --worldlist that accepts either name, path, or both and prints out the corresponding information.
1 parent 48493a9 commit 929792e

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed
 

‎src/main.cpp

+25-14
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ static void print_help(const OptionList &allowed_options);
7474
static void print_allowed_options(const OptionList &allowed_options);
7575
static void print_version();
7676
static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
77-
std::ostream &os);
77+
std::ostream &os, bool print_name = true, bool print_path = true);
7878
static void print_modified_quicktune_values();
7979

8080
static void list_game_ids();
81-
static void list_worlds();
81+
static void list_worlds(bool print_name, bool print_path);
8282
static void 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[]);
@@ -160,9 +160,15 @@ int main(int argc, char *argv[])
160160
return 0;
161161
}
162162

163-
// List worlds if requested
164-
if (cmd_args.exists("world") && cmd_args.get("world") == "list") {
165-
list_worlds();
163+
// List worlds, world names, and world paths if requested
164+
if (cmd_args.exists("worldlist")) {
165+
if (cmd_args.get("worldlist") == "name") {
166+
list_worlds(true, false);
167+
} else if (cmd_args.get("worldlist") == "path") {
168+
list_worlds(false, true);
169+
} else {
170+
list_worlds(true, true);
171+
}
166172
return 0;
167173
}
168174

@@ -252,9 +258,12 @@ static void set_allowed_options(OptionList *allowed_options)
252258
allowed_options->insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
253259
_("Same as --world (deprecated)"))));
254260
allowed_options->insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
255-
_("Set world path (implies local game) ('list' lists all)"))));
261+
_("Set world path (implies local game)"))));
256262
allowed_options->insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
257263
_("Set world by name (implies local game)"))));
264+
allowed_options->insert(std::make_pair("worldlist", ValueSpec(VALUETYPE_STRING,
265+
_("Get list of worlds (implies local game) ('path' lists paths, "
266+
"'name' lists names, 'both' lists both)"))));
258267
allowed_options->insert(std::make_pair("quiet", ValueSpec(VALUETYPE_FLAG,
259268
_("Print to console errors only"))));
260269
allowed_options->insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
@@ -336,24 +345,26 @@ static void list_game_ids()
336345
std::cout << gameid <<std::endl;
337346
}
338347

339-
static void list_worlds()
348+
static void list_worlds(bool print_name, bool print_path)
340349
{
341350
std::cout << _("Available worlds:") << std::endl;
342351
std::vector<WorldSpec> worldspecs = getAvailableWorlds();
343-
print_worldspecs(worldspecs, std::cout);
352+
print_worldspecs(worldspecs, std::cout, print_name, print_path);
344353
}
345354

346355
static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
347-
std::ostream &os)
356+
std::ostream &os, bool print_name, bool print_path)
348357
{
349358
for (const WorldSpec &worldspec : worldspecs) {
350359
std::string name = worldspec.name;
351360
std::string path = worldspec.path;
352-
if (name.find(' ') != std::string::npos)
353-
name = std::string("'").append(name).append("'");
354-
path = std::string("'").append(path).append("'");
355-
name = padStringRight(name, 14);
356-
os << " " << name << " " << path << std::endl;
361+
if (print_name && print_path) {
362+
os << "\t" << name << "\t\t" << path << std::endl;
363+
} else if (print_name) {
364+
os << "\t" << name << std::endl;
365+
} else if (print_path) {
366+
os << "\t" << path << std::endl;
367+
}
357368
}
358369
}
359370

0 commit comments

Comments
 (0)
Please sign in to comment.