Improve --help output

This commit is contained in:
sfan5 2020-03-28 14:02:27 +01:00
parent 539bdbd30c
commit 2ae790c0b7
3 changed files with 63 additions and 27 deletions

View File

@ -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) void TileGenerator::openDb(const std::string &input)
{ {
std::string backend = m_backend; std::string backend = m_backend;

View File

@ -85,12 +85,14 @@ public:
void setExhaustiveSearch(int mode); void setExhaustiveSearch(int mode);
void parseColorsFile(const std::string &fileName); void parseColorsFile(const std::string &fileName);
void setBackend(std::string backend); 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 setZoom(int zoom);
void setScales(uint flags); void setScales(uint flags);
void setDontWriteEmpty(bool f); 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: private:
void parseColorsStream(std::istream &in); void parseColorsStream(std::istream &in);
void openDb(const std::string &input); void openDb(const std::string &input);

View File

@ -1,9 +1,10 @@
#include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <getopt.h> #include <getopt.h>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <map> #include <utility>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
@ -12,30 +13,47 @@
static void usage() static void usage()
{ {
const char *usage_text = "minetestmapper [options]\n" const std::pair<const char*, const char*> options[] = {
" -i/--input <world_path>\n" {"-i/--input", "<world_path>"},
" -o/--output <output_image.png>\n" {"-o/--output", "<output_image.png>"},
" --bgcolor <color>\n" {"--bgcolor", "<color>"},
" --scalecolor <color>\n" {"--scalecolor", "<color>"},
" --playercolor <color>\n" {"--playercolor", "<color>"},
" --origincolor <color>\n" {"--origincolor", "<color>"},
" --drawscale\n" {"--drawscale", ""},
" --drawplayers\n" {"--drawplayers", ""},
" --draworigin\n" {"--draworigin", ""},
" --drawalpha\n" {"--drawalpha", ""},
" --noshading\n" {"--noshading", ""},
" --noemptyimage\n" {"--noemptyimage", ""},
" --min-y <y>\n" {"--min-y", "<y>"},
" --max-y <y>\n" {"--max-y", "<y>"},
" --backend <backend>\n" {"--backend", "<backend>"},
" --geometry x:y+w+h\n" {"--geometry", "x:y+w+h"},
" --extent\n" {"--extent", ""},
" --zoom <zoomlevel>\n" {"--zoom", "<zoomlevel>"},
" --colors <colors.txt>\n" {"--colors", "<colors.txt>"},
" --scales [t][b][l][r]\n" {"--scales", "[t][b][l][r]"},
" --exhaustive never|y|full|auto\n" {"--exhaustive", "never|y|full|auto"},
"Color format: '#000000'\n"; };
std::cout << usage_text; 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) static bool file_exists(const std::string &path)