Skip to content

Commit 2ae790c

Browse files
committedMar 28, 2020
Improve --help output
1 parent 539bdbd commit 2ae790c

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed
 

‎TileGenerator.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,22 @@ void TileGenerator::parseColorsStream(std::istream &in)
311311
}
312312
}
313313

314+
std::set<std::string> TileGenerator::getSupportedBackends()
315+
{
316+
std::set<std::string> r;
317+
r.insert("sqlite3");
318+
#if USE_POSTGRESQL
319+
r.insert("postgresql");
320+
#endif
321+
#if USE_LEVELDB
322+
r.insert("leveldb");
323+
#endif
324+
#if USE_REDIS
325+
r.insert("redis");
326+
#endif
327+
return r;
328+
}
329+
314330
void TileGenerator::openDb(const std::string &input)
315331
{
316332
std::string backend = m_backend;

‎include/TileGenerator.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ class TileGenerator
8585
void setExhaustiveSearch(int mode);
8686
void parseColorsFile(const std::string &fileName);
8787
void setBackend(std::string backend);
88-
void generate(const std::string &input, const std::string &output);
89-
void printGeometry(const std::string &input);
9088
void setZoom(int zoom);
9189
void setScales(uint flags);
9290
void setDontWriteEmpty(bool f);
9391

92+
void generate(const std::string &input, const std::string &output);
93+
void printGeometry(const std::string &input);
94+
static std::set<std::string> getSupportedBackends();
95+
9496
private:
9597
void parseColorsStream(std::istream &in);
9698
void openDb(const std::string &input);

‎mapper.cpp

+43-25
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#include <cstdio>
12
#include <cstdlib>
23
#include <cstring>
34
#include <getopt.h>
45
#include <fstream>
56
#include <iostream>
6-
#include <map>
7+
#include <utility>
78
#include <string>
89
#include <sstream>
910
#include <stdexcept>
@@ -12,30 +13,47 @@
1213

1314
static void usage()
1415
{
15-
const char *usage_text = "minetestmapper [options]\n"
16-
" -i/--input <world_path>\n"
17-
" -o/--output <output_image.png>\n"
18-
" --bgcolor <color>\n"
19-
" --scalecolor <color>\n"
20-
" --playercolor <color>\n"
21-
" --origincolor <color>\n"
22-
" --drawscale\n"
23-
" --drawplayers\n"
24-
" --draworigin\n"
25-
" --drawalpha\n"
26-
" --noshading\n"
27-
" --noemptyimage\n"
28-
" --min-y <y>\n"
29-
" --max-y <y>\n"
30-
" --backend <backend>\n"
31-
" --geometry x:y+w+h\n"
32-
" --extent\n"
33-
" --zoom <zoomlevel>\n"
34-
" --colors <colors.txt>\n"
35-
" --scales [t][b][l][r]\n"
36-
" --exhaustive never|y|full|auto\n"
37-
"Color format: '#000000'\n";
38-
std::cout << usage_text;
16+
const std::pair<const char*, const char*> options[] = {
17+
{"-i/--input", "<world_path>"},
18+
{"-o/--output", "<output_image.png>"},
19+
{"--bgcolor", "<color>"},
20+
{"--scalecolor", "<color>"},
21+
{"--playercolor", "<color>"},
22+
{"--origincolor", "<color>"},
23+
{"--drawscale", ""},
24+
{"--drawplayers", ""},
25+
{"--draworigin", ""},
26+
{"--drawalpha", ""},
27+
{"--noshading", ""},
28+
{"--noemptyimage", ""},
29+
{"--min-y", "<y>"},
30+
{"--max-y", "<y>"},
31+
{"--backend", "<backend>"},
32+
{"--geometry", "x:y+w+h"},
33+
{"--extent", ""},
34+
{"--zoom", "<zoomlevel>"},
35+
{"--colors", "<colors.txt>"},
36+
{"--scales", "[t][b][l][r]"},
37+
{"--exhaustive", "never|y|full|auto"},
38+
};
39+
const char *top_text =
40+
"minetestmapper -i <world_path> -o <output_image.png> [options]\n"
41+
"Generate an overview image of a Minetest map.\n"
42+
"\n"
43+
"Options:\n";
44+
const char *bottom_text =
45+
"\n"
46+
"Color format: hexadecimal '#RRGGBB', e.g. '#FF0000' = red\n";
47+
48+
printf("%s", top_text);
49+
for (const auto &p : options)
50+
printf(" %-18s%s\n", p.first, p.second);
51+
printf("%s", bottom_text);
52+
auto backends = TileGenerator::getSupportedBackends();
53+
printf("Supported backends: ");
54+
for (auto s : backends)
55+
printf("%s ", s.c_str());
56+
printf("\n");
3957
}
4058

4159
static bool file_exists(const std::string &path)

0 commit comments

Comments
 (0)
Please sign in to comment.