Skip to content

Commit

Permalink
Improve --help output
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 28, 2020
1 parent 539bdbd commit 2ae790c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
16 changes: 16 additions & 0 deletions TileGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ void TileGenerator::parseColorsStream(std::istream &in)
}
}

std::set<std::string> TileGenerator::getSupportedBackends()
{
std::set<std::string> r;
r.insert("sqlite3");
#if USE_POSTGRESQL
r.insert("postgresql");
#endif
#if USE_LEVELDB
r.insert("leveldb");
#endif
#if USE_REDIS
r.insert("redis");
#endif
return r;
}

void TileGenerator::openDb(const std::string &input)
{
std::string backend = m_backend;
Expand Down
6 changes: 4 additions & 2 deletions include/TileGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,14 @@ class TileGenerator
void setExhaustiveSearch(int mode);
void parseColorsFile(const std::string &fileName);
void setBackend(std::string backend);
void generate(const std::string &input, const std::string &output);
void printGeometry(const std::string &input);
void setZoom(int zoom);
void setScales(uint flags);
void setDontWriteEmpty(bool f);

void generate(const std::string &input, const std::string &output);
void printGeometry(const std::string &input);
static std::set<std::string> getSupportedBackends();

private:
void parseColorsStream(std::istream &in);
void openDb(const std::string &input);
Expand Down
68 changes: 43 additions & 25 deletions mapper.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <getopt.h>
#include <fstream>
#include <iostream>
#include <map>
#include <utility>
#include <string>
#include <sstream>
#include <stdexcept>
Expand All @@ -12,30 +13,47 @@

static void usage()
{
const char *usage_text = "minetestmapper [options]\n"
" -i/--input <world_path>\n"
" -o/--output <output_image.png>\n"
" --bgcolor <color>\n"
" --scalecolor <color>\n"
" --playercolor <color>\n"
" --origincolor <color>\n"
" --drawscale\n"
" --drawplayers\n"
" --draworigin\n"
" --drawalpha\n"
" --noshading\n"
" --noemptyimage\n"
" --min-y <y>\n"
" --max-y <y>\n"
" --backend <backend>\n"
" --geometry x:y+w+h\n"
" --extent\n"
" --zoom <zoomlevel>\n"
" --colors <colors.txt>\n"
" --scales [t][b][l][r]\n"
" --exhaustive never|y|full|auto\n"
"Color format: '#000000'\n";
std::cout << usage_text;
const std::pair<const char*, const char*> options[] = {
{"-i/--input", "<world_path>"},
{"-o/--output", "<output_image.png>"},
{"--bgcolor", "<color>"},
{"--scalecolor", "<color>"},
{"--playercolor", "<color>"},
{"--origincolor", "<color>"},
{"--drawscale", ""},
{"--drawplayers", ""},
{"--draworigin", ""},
{"--drawalpha", ""},
{"--noshading", ""},
{"--noemptyimage", ""},
{"--min-y", "<y>"},
{"--max-y", "<y>"},
{"--backend", "<backend>"},
{"--geometry", "x:y+w+h"},
{"--extent", ""},
{"--zoom", "<zoomlevel>"},
{"--colors", "<colors.txt>"},
{"--scales", "[t][b][l][r]"},
{"--exhaustive", "never|y|full|auto"},
};
const char *top_text =
"minetestmapper -i <world_path> -o <output_image.png> [options]\n"
"Generate an overview image of a Minetest map.\n"
"\n"
"Options:\n";
const char *bottom_text =
"\n"
"Color format: hexadecimal '#RRGGBB', e.g. '#FF0000' = red\n";

printf("%s", top_text);
for (const auto &p : options)
printf(" %-18s%s\n", p.first, p.second);
printf("%s", bottom_text);
auto backends = TileGenerator::getSupportedBackends();
printf("Supported backends: ");
for (auto s : backends)
printf("%s ", s.c_str());
printf("\n");
}

static bool file_exists(const std::string &path)
Expand Down

0 comments on commit 2ae790c

Please sign in to comment.