# HG changeset patch # User David Demelier # Date 1637498640 -3600 # Node ID fc89091b834550b4c5c3811401d76d3d18500517 # Parent ef91ec313ea2de987d5723d904541cdd684ead25 irccd: add paths subcommand diff -r ef91ec313ea2 -r fc89091b8345 CHANGES.md --- a/CHANGES.md Thu Nov 18 15:11:23 2021 +0100 +++ b/CHANGES.md Sun Nov 21 13:44:00 2021 +0100 @@ -17,6 +17,7 @@ someone is present on a channel. - It is now possible to change uid/gid of the transport socket file. The file is also created with permissions 664. +- A new `paths` command has been added to show default paths. irccdctl -------- diff -r ef91ec313ea2 -r fc89091b8345 irccd/main.c --- a/irccd/main.c Thu Nov 18 15:11:23 2021 +0100 +++ b/irccd/main.c Sun Nov 21 13:44:00 2021 +0100 @@ -85,11 +85,9 @@ return i; } -static int -run(int argc, char **argv) +static void +run_info(void) { - (void)argc; - #if defined(IRCCD_WITH_JS) const char *with_js = "yes"; #else @@ -101,14 +99,71 @@ const char *with_ssl = "no"; #endif - if (strcmp(argv[0], "version") == 0) - puts(IRCCD_VERSION); - else if (strcmp(argv[0], "info") == 0) { - printf("%-16s%s\n", "javascript:", with_js); - printf("%-16s%s\n", "ssl:", with_ssl); + printf("%-16s%s\n", "javascript:", with_js); + printf("%-16s%s\n", "ssl:", with_ssl); +} + +static void +run_paths(void) +{ + struct irc_plugin_loader *ld; + char paths[IRC_PATHS_LEN], extensions[IRC_EXTENSIONS_LEN], *p, *token; + + printf("%-16s%s\n", "cache:", IRCCD_CACHEDIR); + printf("%-16s%s\n", "config:", IRCCD_SYSCONFDIR); + printf("%-16s%s\n", "lib:", IRCCD_LIBDIR); + printf("%-16s%s\n", "data:", IRCCD_DATADIR); + printf("\n"); + + LL_FOREACH(irc.plugin_loaders, ld) { + printf("Plugins with extensions:"); + irc_util_strlcpy(extensions, ld->extensions, sizeof (extensions)); + irc_util_strlcpy(paths, ld->paths, sizeof (paths)); + + for (p = extensions; (token = strtok_r(p, ":", &p)); ) + printf(" %s", token); + + printf("\n"); + + for (p = paths; (token = strtok_r(p, ":", &p)); ) + printf(" %s\n", token); + + if (ld->next) + printf("\n"); + } +} + +static void +run_version(void) +{ + puts(IRCCD_VERSION); +} + +static int +run(int argc, char **argv) +{ + (void)argc; + + static struct { + const char *name; + void (*exec)(void); + } cmds[] = { + { "info", run_info }, + { "paths", run_paths }, + { "version", run_version }, + { NULL, NULL } + }; + + for (size_t i = 0; cmds[i].name; ++i) { + if (strcmp(cmds[i].name, argv[0]) == 0) { + cmds[i].exec(); + return 0; + } } - return 0; + irc_util_die("abort: unknown command: %s\n", argv[0]); + + return 1; } static void @@ -260,10 +315,11 @@ argc -= optind; argv += optind; + init(); + if (argc > 0) return run(argc, argv); - init(); load(); /* We apply now so it overrides configuration file. */ diff -r ef91ec313ea2 -r fc89091b8345 man/irccd.1 --- a/man/irccd.1 Thu Nov 18 15:11:23 2021 +0100 +++ b/man/irccd.1 Sun Nov 21 13:44:00 2021 +0100 @@ -28,6 +28,8 @@ .Nm .Ar info .Nm +.Ar paths +.Nm .Ar version .\" DESCRIPTION .Sh DESCRIPTION @@ -56,6 +58,8 @@ .It Cm version Get the irccd version. if Mercurial was available when building irccd then the current revision is bundled in the output. +.It Cm paths +Shows where irccd will load plugins, configuration files and such. .El .\" PLUGINS .Sh PLUGINS