From f379ffb8ed9bba0dafc2a7c1430ccb1a2517f99c Mon Sep 17 00:00:00 2001 From: Ryan Farley Date: Fri, 11 Jun 2021 04:40:08 -0500 Subject: Override options from command line Allow any configuration option to be overridden with -o/--override 'section.key=value' arguments, as suggested in #554 update completitions for override slight refactoring to ease footclient support --- main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 82795424..52ebaca6 100644 --- a/main.c +++ b/main.c @@ -62,6 +62,7 @@ print_usage(const char *prog_name) "Options:\n" " -c,--config=PATH load configuration from PATH ($XDG_CONFIG_HOME/foot/foot.ini)\n" " -C,--check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n" + " -o,--override [section.]key=value override configuration option\n" " -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\n" " -t,--term=TERM value to set the environment variable TERM to (%s)\n" " -T,--title=TITLE initial window title (foot)\n" @@ -165,6 +166,7 @@ main(int argc, char *const *argv) static const struct option longopts[] = { {"config", required_argument, NULL, 'c'}, {"check-config", no_argument, NULL, 'C'}, + {"override", required_argument, NULL, 'o'}, {"term", required_argument, NULL, 't'}, {"title", required_argument, NULL, 'T'}, {"app-id", required_argument, NULL, 'a'}, @@ -210,9 +212,11 @@ main(int argc, char *const *argv) enum log_colorize log_colorize = LOG_COLORIZE_AUTO; bool log_syslog = true; user_notifications_t user_notifications = tll_init(); + config_override_t overrides = tll_init(); while (true) { - int c = getopt_long(argc, argv, "+c:Ct:T:a:LD:f:w:W:s::HmFPp:d:l::Svh", longopts, NULL); + int c = getopt_long(argc, argv, "+c:Co:t:T:a:LD:f:w:W:s::HmFPp:d:l::Svh", longopts, NULL); + if (c == -1) break; @@ -225,6 +229,10 @@ main(int argc, char *const *argv) check_config = true; break; + case 'o': + tll_push_back(overrides, optarg); + break; + case 't': conf_term = optarg; break; @@ -404,7 +412,9 @@ main(int argc, char *const *argv) } struct config conf = {NULL}; - if (!config_load(&conf, conf_path, &user_notifications, check_config)) { + bool conf_successful = config_load(&conf, conf_path, &user_notifications, &overrides, check_config); + tll_free(overrides); + if (!conf_successful) { config_free(conf); return ret; } -- cgit v1.3