changeset 848:800b025f9842

irccd: add info and version, closes #1672
author David Demelier <markand@malikania.fr>
date Wed, 10 Jul 2019 20:15:00 +0200
parents a23b7b574ed2
children 64f8f82ab110
files CHANGES.md irccd/main.cpp
diffstat 2 files changed, 39 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.md	Wed Jul 10 20:10:00 2019 +0200
+++ b/CHANGES.md	Wed Jul 10 20:15:00 2019 +0200
@@ -15,7 +15,8 @@
 - The origin in rule is now first class value (#947),
 - New option `ipv4` in `[transport]` (#945),
 - New option `ipv4` in `[server]` (#945),
-- Section `[format]` is renamed to `[templates]` (#1671).
+- Section `[format]` is renamed to `[templates]` (#1671),
+- New commands are available as irccd arguments `info` and `version` (#1672).
 
 irccdctl:
 
--- a/irccd/main.cpp	Wed Jul 10 20:10:00 2019 +0200
+++ b/irccd/main.cpp	Wed Jul 10 20:15:00 2019 +0200
@@ -49,39 +49,46 @@
 
 void usage()
 {
-	std::cerr << "usage: irccd [options...]\n\n";
+	std::cerr << "usage: irccd [options...]\n";
+	std::cerr << "       irccd info\n";
+	std::cerr << "       irccd version\n\n";
 	std::cerr << "Available options:\n";
 	std::cerr << "  -c, --config file       specify the configuration file\n";
 	std::cerr << "  -h, --help              show this help\n";
 	std::cerr << "  -v, --verbose           be verbose\n";
-	std::cerr << "      --version           show the version\n";
 	std::exit(1);
 }
 
 // }}}
 
+// {{{ info
+
+void info()
+{
+	bool ssl = false;
+	bool js = false;
+
+#if defined(IRCCD_HAVE_SSL)
+	ssl = true;
+#endif
+#if defined(IRCCD_HAVE_JS)
+	js = true;
+#endif
+
+	std::cout << std::boolalpha;
+	std::cout << "ssl:              " << ssl << std::endl;
+	std::cout << "javascript:       " << js << std::endl;
+
+	std::exit(0);
+}
+
+// }}}
+
 // {{{ version
 
-void version(const option::result& options)
+void version()
 {
 	std::cout << IRCCD_VERSION << std::endl;
-
-	if (options.count("-v") > 0 || options.count("--verbose") > 0) {
-		bool ssl = false;
-		bool js = false;
-
-#if defined(IRCCD_HAVE_SSL)
-		ssl = true;
-#endif
-#if defined(IRCCD_HAVE_JS)
-		js = true;
-#endif
-
-		std::cout << std::boolalpha << std::endl;
-		std::cout << "ssl:		  " << ssl << std::endl;
-		std::cout << "javascript:   " << js << std::endl;
-	}
-
 	std::exit(0);
 }
 
@@ -117,7 +124,6 @@
 			{ "--help",     false   },
 			{ "-v",         false   },
 			{ "--verbose",  false   },
-			{ "--version",  false   }
 		};
 
 		result = option::read(argc, argv, options);
@@ -126,9 +132,6 @@
 			if (pair.first == "-h" || pair.first == "--help")
 				usage();
 				// NOTREACHED
-			if (pair.first == "--version")
-				version(result);
-				// NOTREACHED
 			if (pair.first == "-v" || pair.first == "--verbose")
 				instance->get_log().set_verbose(true);
 		}
@@ -195,6 +198,16 @@
 
 	const auto options = parse(argc, argv);
 
+	if (argc > 0) {
+		if (std::strcmp(argv[0], "info") == 0)
+			irccd::daemon::info();
+			// NOTREACHED
+		if (std::strcmp(argv[0], "version") == 0)
+			irccd::daemon::version();
+			// NOTREACHED
+	}
+
+
 	try {
 		instance->set_config(open(options));
 		instance->load();