From 326076c46cbdc7afc9bcc2df56aa0b95d174f927 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Tue, 12 Sep 2023 15:58:43 -0500 Subject: Add version subcommand --- README.md | 10 ++++++---- src/main.cpp | 10 ++++++++-- src/version.hpp | 3 +++ 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/version.hpp diff --git a/README.md b/README.md index 6153e1d..f41a5d8 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,12 @@ specific components of the configurations and outputs them to `stdout`. The `ins installs the configuration with the appropriate permissions. ```plaintext -Usage: ./wg2nd { install, generate } [ OPTIONS ] { -h, CONFIG_FILE } +Usage: wg2nd { install, generate } [ OPTIONS ] { -h, CONFIG_FILE } +Usage: wg2nd version - CONFIG_FILE is the complete path to a WireGuard configuration file used by - `wg-quick`. `wg2nd` converts the WireGuard configuration to networkd files. + CONFIG_FILE is the complete path to a WireGuard configuration file, used by + `wg-quick`. `wg2nd` will convert the WireGuard configuration to networkd + files. The generated configurations are functionally equivalent to `wg-quick(8)` with the following exceptions: @@ -127,7 +129,7 @@ Usage: ./wg2nd { install, generate } [ OPTIONS ] { -h, CONFIG_FILE } ``` ```plaintext -Usage: ./wg2nd install [ -h ] [ -f FILE_NAME ] [ -o OUTPUT_PATH ] CONFIG_FILE +Usage: wg2nd install [ -h ] [ -f FILE_NAME ] [ -o OUTPUT_PATH ] CONFIG_FILE `wg2nd install` translates `wg-quick(8)` configuration into corresponding `networkd` configuration and installs the resulting files in `OUTPUT_PATH`. diff --git a/src/main.cpp b/src/main.cpp index a5dbf8b..e685e10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,8 @@ * Copyright (C) 2023 Alex David */ +#include "version.hpp" + #include #include #include @@ -94,12 +96,14 @@ constexpr char const * DEFAULT_OUTPUT_PATH = "/etc/systemd/network/"; */ void die_usage(const char *prog) { - err("Usage: %s { install, generate } [ OPTIONS ] { -h, CONFIG_FILE }", prog); + err("Usage: %s { install, generate } [ OPTIONS ] { -h, CONFIG_FILE }", prog); + err("Usage: %s version", prog); die("Use -h for help"); } void print_help(const char *prog) { - err("Usage: %s { install, generate } [ OPTIONS ] { -h, CONFIG_FILE }\n", prog); + err("Usage: %s { install, generate } [ OPTIONS ] { -h, CONFIG_FILE }", prog); + err("Usage: %s version\n", prog); err(" CONFIG_FILE is the complete path to a WireGuard configuration file, used by"); err(" `wg-quick`. `wg2nd` will convert the WireGuard configuration to networkd"); err(" files.\n"); @@ -437,6 +441,8 @@ int main(int argc, char **argv) { return wg2nd_generate(prog, argc - 1, argv + 1); } else if (action == "install") { return wg2nd_install(prog, argc - 1, argv + 1); + } else if (action == "version") { + printf("%s\n", VERSION); } else if (action == "-h" || action == "--help") { print_help(prog); } else { diff --git a/src/version.hpp b/src/version.hpp new file mode 100644 index 0000000..3e8675e --- /dev/null +++ b/src/version.hpp @@ -0,0 +1,3 @@ +#pragma once + +constexpr char const * VERSION = "v0.1.0"; -- cgit v1.2.3