main: add --check-config command line option

This commit is contained in:
Daniel Eklöf 2020-07-29 17:48:22 +02:00
parent d11d374252
commit 86e7cb04c4
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 19 additions and 1 deletions

View file

@ -21,6 +21,7 @@
**scrollback-indicator-format** options in `footrc`
(https://codeberg.org/dnkl/foot/issues/42).
* Key bindings in _scollback search_ mode are now configurable.
* `--check-config` command line option.
### Deprecated

View file

@ -3,6 +3,7 @@
_arguments \
-s -S -C \
'(-c --config)'{-c,--config}'[path to configuration file (XDG_CONFIG_HOME/footrc)]:config:_files' \
'--check-config[verify configuration and exit with 0 if ok, otherwise exit with 1]' \
'(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \
'(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \
'--title[initial window title]:()' \

View file

@ -15,6 +15,10 @@ arguments, to execute (instead of the default shell).
*-c*,*--config*=_PATH_
Path to configuration file. Default: *XDG_CONFIG_HOME/footrc*.
*--check-config*
Verify configuration and then exit with 0 if ok, otherwise exit
with 1.
*-f*,*--font*=_FONT_
Comma separated list of fonts to use, in fontconfig format (see
*FONT FORMAT*).

14
main.c
View file

@ -46,6 +46,7 @@ print_usage(const char *prog_name)
"\n"
"Options:\n"
" -c,--config=PATH load configuration from PATH (XDG_CONFIG_HOME/footrc)\n"
" --check-config verify configuration, exit with 0 if ok, otherwise exit with 1\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 (foot)\n"
" --title=TITLE initial window title (foot)\n"
@ -142,6 +143,7 @@ main(int argc, char *const *argv)
static const struct option longopts[] = {
{"config", required_argument, NULL, 'c'},
{"check-config", no_argument, NULL, 'C'},
{"term", required_argument, NULL, 't'},
{"title", required_argument, NULL, 'T'},
{"app-id", required_argument, NULL, 'a'},
@ -161,6 +163,7 @@ main(int argc, char *const *argv)
{NULL, no_argument, NULL, 0},
};
bool check_config = false;
const char *conf_path = NULL;
const char *conf_term = NULL;
const char *conf_title = NULL;
@ -181,7 +184,7 @@ main(int argc, char *const *argv)
bool log_syslog = true;
while (true) {
int c = getopt_long(argc, argv, "+c:t:a:Lf:g:s::Pp:l::Svh", longopts, NULL);
int c = getopt_long(argc, argv, "+c:Ct:a:Lf:g:s::Pp:l::Svh", longopts, NULL);
if (c == -1)
break;
@ -190,6 +193,10 @@ main(int argc, char *const *argv)
conf_path = optarg;
break;
case 'C':
check_config = true;
break;
case 't':
conf_term = optarg;
break;
@ -320,6 +327,11 @@ main(int argc, char *const *argv)
return ret;
}
if (check_config) {
config_free(conf);
return EXIT_SUCCESS;
}
setlocale(LC_CTYPE, "");
LOG_INFO("locale: %s", setlocale(LC_CTYPE, NULL));
if (!locale_is_utf8()) {