diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-30 08:54:52 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-30 08:54:52 +0200 |
commit | 769457c165488fb8059ecb843a1c200f69dce95d (patch) | |
tree | 8ea46bc8f22454681130c7ce9958443ca1e4d440 /minecctl | |
parent | a89a0f918925a662503c1bcb28bdb06ab9b7ef25 (diff) |
Centralize scfg validation and use in minecctl to implement a lint command
Diffstat (limited to 'minecctl')
-rw-r--r-- | minecctl/minecctl-commands.h | 5 | ||||
-rw-r--r-- | minecctl/minecctl.c | 12 | ||||
-rw-r--r-- | minecctl/misc-commands.c | 24 | ||||
-rw-r--r-- | minecctl/misc-commands.h | 2 |
4 files changed, 41 insertions, 2 deletions
diff --git a/minecctl/minecctl-commands.h b/minecctl/minecctl-commands.h index e8bb132..b1729f0 100644 --- a/minecctl/minecctl-commands.h +++ b/minecctl/minecctl-commands.h @@ -4,6 +4,7 @@ enum commands { CMD_INVALID = 0, CMD_LIST, + CMD_LINT, CMD_STATUS, CMD_PING, CMD_STOP, @@ -22,6 +23,10 @@ static struct command_list { .cmd = CMD_LIST, }, { + .name = "lint", + .cmd = CMD_LINT, + }, + { .name = "status", .cmd = CMD_STATUS, }, diff --git a/minecctl/minecctl.c b/minecctl/minecctl.c index 231b150..69286fc 100644 --- a/minecctl/minecctl.c +++ b/minecctl/minecctl.c @@ -69,7 +69,7 @@ _noreturn_ static void usage(bool no_error) " -m, --mc-address=ADDR connect to Minecraft server at ADDR\n" " (only relevant for some commands, can also\n" " use environment variable MC_ADDRESS)\n" - " -c, --cfgdir=DIR look for server configurations in DIR\n" + " -c, --cfgdir=DIR look for server configuration files in DIR\n" " (default: %s)\n" " -f, --force stop server even if it has players\n" " -v, --verbose enable extra logging\n" @@ -77,6 +77,7 @@ _noreturn_ static void usage(bool no_error) "\n" "Valid commands:\n" " list list known servers\n" + " lint check validity of server configuration files\n" " status [SERVER] show status of SERVER (or all known servers)\n" " ping [SERVER] check if SERVER is running\n" " stop [SERVER] stop SERVER\n" @@ -225,6 +226,13 @@ static void parse_command(struct cfg *cfg, char *const *argv) } cfg->cmd = do_list; break; + case CMD_LINT: + if (*argv) { + error("Too many arguments"); + usage(false); + } + cfg->cmd = do_lint; + break; case CMD_STOPALL: if (*argv) { error("Too many arguments"); @@ -300,7 +308,7 @@ static void parse_cmdline(struct cfg *cfg, int argc, char *const *argv) cfg->cfgdir = DEFAULT_CFG_DIR; - /* FIXME: add lint and debug options */ + /* FIXME: add debug option */ while (true) { int option_index = 0; diff --git a/minecctl/misc-commands.c b/minecctl/misc-commands.c index f20cac5..1268138 100644 --- a/minecctl/misc-commands.c +++ b/minecctl/misc-commands.c @@ -17,6 +17,30 @@ bool do_list(struct cfg *cfg) return true; } +bool do_lint(struct cfg *cfg) +{ + struct server *server; + bool rv = true; + + /* server->scfg.filename check excludes servers created from cmdline */ + list_for_each_entry(server, &cfg->servers, list) { + if (!server->scfg.filename) + continue; + + info("%s", server->name); + + /* FIXME: should return bool */ + server_read_config(cfg, server); + + if (!scfg_validate(&server->scfg)) { + error("%s: invalid", server->name); + rv = false; + } + } + + return rv; +} + bool do_pcount(struct cfg *cfg) { unsigned x, y; diff --git a/minecctl/misc-commands.h b/minecctl/misc-commands.h index 1a4363f..eb03fd9 100644 --- a/minecctl/misc-commands.h +++ b/minecctl/misc-commands.h @@ -3,6 +3,8 @@ bool do_list(struct cfg *cfg); +bool do_lint(struct cfg *cfg); + bool do_pcount(struct cfg *cfg); #endif |