# HG changeset patch
# Node ID d0c9ffc8d90d
# Parent  aff19a0cd866
diff --git a/meson.build b/meson.build
--- a/meson.build
+++ b/meson.build
@@ -108,6 +108,7 @@
 ###############################################################################
 subdir('po')
 subdir('traversity')
+subdir('traversity-cli')
 subdir('traversity-test')
 
 # Output our configuration file.
diff --git a/traversity-cli/meson.build b/traversity-cli/meson.build
new file mode 100644
--- /dev/null
+++ b/traversity-cli/meson.build
@@ -0,0 +1,8 @@
+TRAVERSITY_CLI_SOURCES = [
+	'traversityclicore.c',
+]
+
+executable('traversity',
+	TRAVERSITY_CLI_SOURCES,
+	dependencies : [traversity_dep, GLIB, GOBJECT, TEMPLATE_GLIB],
+	install: true)
diff --git a/traversity-cli/traversityclicore.c b/traversity-cli/traversityclicore.c
new file mode 100644
--- /dev/null
+++ b/traversity-cli/traversityclicore.c
@@ -0,0 +1,105 @@
+/*
+ * Traversity - NAT Traversal Client Library
+ * Copyright (C) Traversity Developers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see https://www.gnu.org/licenses/.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gprintf.h>
+
+#include <glib-object.h>
+
+/******************************************************************************
+ * Command Line Handling
+ *****************************************************************************/
+static const char *summary = \
+	N_("traversity-cli is an interface to the Traversity NAT Traversal Client "
+	   "library. It can be used to discover your external IP address via "
+	   "multiple methods as well as dynamically open a port on a gateway "
+	   "device.");
+
+static const char *description = \
+	N_("Available Commands:\n"
+	   "  version  Displays the version and exits");
+
+static void
+traversity_cli_option_verbose_cb(G_GNUC_UNUSED const char *name,
+                                 G_GNUC_UNUSED const char *value,
+                                 G_GNUC_UNUSED gpointer data,
+                                 G_GNUC_UNUSED GError **error)
+{
+	g_setenv("G_MESSAGES_DEBUG", "all", TRUE);
+}
+
+/******************************************************************************
+ * Exports
+ *****************************************************************************/
+int
+main(int argc, char *argv[]) {
+	GError *error = NULL;
+	GOptionContext *ctx = NULL;
+	GOptionEntry entries[] = {
+		{
+			"verbose", 'v', G_OPTION_FLAG_NO_ARG,
+			G_OPTION_ARG_CALLBACK, traversity_cli_option_verbose_cb,
+			C_(GETTEXT_PACKAGE " --help", "increase the log level"), NULL
+		}, {
+			NULL
+		}
+	};
+	const char *command = NULL;
+	int ret = EXIT_SUCCESS;
+
+	ctx = g_option_context_new("[version]");
+	g_option_context_add_main_entries(ctx, entries, GETTEXT_PACKAGE);
+	g_option_context_set_translation_domain(ctx, GETTEXT_PACKAGE);
+	g_option_context_set_summary(ctx, summary);
+	g_option_context_set_description(ctx, description);
+	g_option_context_set_ignore_unknown_options(ctx, TRUE);
+	g_option_context_parse(ctx, &argc, &argv, &error);
+	g_clear_pointer(&ctx, g_option_context_free);
+
+	if(error != NULL) {
+		g_printerr("%s\n", error->message);
+
+		g_clear_error(&error);
+
+		return EXIT_FAILURE;
+	}
+
+	if(argc == 1) {
+		g_printerr(_("no command specified\n"));
+
+		return EXIT_FAILURE;
+	}
+
+	if(argc > 2) {
+		g_printerr(_("only one command may be specified\n"));
+
+		return EXIT_FAILURE;
+	}
+
+	command = argv[1];
+	if(g_strcmp0(command, "version") == 0) {
+		g_printf("traversity %s\n", VERSION);
+	} else {
+		g_printerr("unknown command '%s'\n", command);
+
+		ret = EXIT_FAILURE;
+	}
+
+	return ret;
+}
