changeset 1118:fc89091b8345

irccd: add paths subcommand
author David Demelier <markand@malikania.fr>
date Sun, 21 Nov 2021 13:44:00 +0100
parents ef91ec313ea2
children 74aba215dc3c
files CHANGES.md irccd/main.c man/irccd.1
diffstat 3 files changed, 72 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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
 --------
--- 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. */
--- 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