summaryrefslogtreecommitdiff
path: root/minecctl/minecctl.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-07-09 20:36:15 +0200
committerDavid Härdeman <david@hardeman.nu>2020-07-09 20:36:15 +0200
commitdd6321c0acf7b0570811200a205cc4104bee49c7 (patch)
tree52da75427a0c1d237806fbebba23025afd79d28d /minecctl/minecctl.c
parent4ae60696aed938347cc1cf2a5d8f5a2b86292132 (diff)
Implement a basic init command in minecctl to create an initial example config
Diffstat (limited to 'minecctl/minecctl.c')
-rw-r--r--minecctl/minecctl.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/minecctl/minecctl.c b/minecctl/minecctl.c
index 56e386e..b374f18 100644
--- a/minecctl/minecctl.c
+++ b/minecctl/minecctl.c
@@ -20,7 +20,6 @@
#include "rcon-commands.h"
#include "misc-commands.h"
#include "misc.h"
-#include "config.h"
static void dump_server(struct server *server)
{
@@ -131,12 +130,15 @@ void dump_config(struct cfg *cfg)
info("Configuration");
info("┌────────────");
- info("│ cfgdir : %s", cfg->cfgdir);
+ info("│ dir_path : %s", cfg->dir_path);
+ info("│ dir : %p", cfg->dir);
info("│ rcon_password : %s", cfg->rcon_password);
info("│ rcon_addrstr : %s", cfg->rcon_addrstr);
info("│ mc_addrstr : %s", cfg->mc_addrstr);
info("│ cmd : %p", cfg->cmd);
info("│ force stop : %s", cfg->force_stop ? "yes" : "no");
+ info("│ default set : %s", cfg->default_set ? "yes" : "no");
+ info("│ servers loaded: %s", cfg->server_list_loaded ? "yes" : "no");
info("│ commands%s", cfg->commands ? "" : " : none");
if (cfg->commands) {
for (char *const *cmd = cfg->commands; *cmd; cmd++)
@@ -154,6 +156,7 @@ _noreturn_ static void usage(bool no_error)
info("Usage: %s [OPTIONS...] COMMAND\n"
"\n"
"Valid commands:\n"
+ " init perform initial setup\n"
" list list known servers\n"
" lint check validity of server configuration files\n"
" info [SERVER] show information about a running SERVER (or all known servers)\n"
@@ -176,7 +179,6 @@ _noreturn_ static void usage(bool no_error)
" (only relevant for some commands, can also\n"
" use environment variable MC_ADDRESS)\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"
" -d, --debug enable debugging information\n"
@@ -186,7 +188,7 @@ _noreturn_ static void usage(bool no_error)
" the command and vice versa.\n"
"\n"
"See the minecctl(1) man page for details.\n",
- program_invocation_short_name, DEFAULT_CFG_DIR);
+ program_invocation_short_name);
exit(no_error ? EXIT_FAILURE : EXIT_SUCCESS);
}
@@ -315,6 +317,13 @@ static void parse_command(struct cfg *cfg, char *const *argv)
}
switch (cmd) {
+ case CMD_INIT:
+ if (*argv) {
+ error("Too many arguments");
+ usage(false);
+ }
+ cfg->cmd = do_init;
+ break;
case CMD_LIST:
if (*argv) {
error("Too many arguments");
@@ -402,8 +411,6 @@ static void parse_cmdline(struct cfg *cfg, int argc, char *const *argv)
usage(false);
}
- cfg->cfgdir = DEFAULT_CFG_DIR;
-
while (true) {
int option_index = 0;
/* clang-format off */
@@ -437,7 +444,7 @@ static void parse_cmdline(struct cfg *cfg, int argc, char *const *argv)
cfg->mc_addrstr = xstrdup(optarg);
break;
case 'c':
- cfg->cfgdir = optarg;
+ cfg->dir_path = optarg;
break;
case 'v':
debug_mask |= DBG_VERBOSE;
@@ -488,8 +495,6 @@ int main(int argc, char *const *argv)
parse_cmdline(&cfg, argc, argv);
- server_load_all_known(&cfg);
-
parse_command(&cfg, &argv[optind]);
if (!cfg.cmd) {
@@ -509,5 +514,7 @@ out:
strv_free(cfg.commands);
xfree(cfg.rcon_addrstr);
xfree(cfg.mc_addrstr);
+ if (cfg.dir)
+ closedir(cfg.dir);
exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
}