From 38b1b8114e5d31018eed23210ea639a5ea881ccc Mon Sep 17 00:00:00 2001 From: Oliver 'kfsone' Smith Date: Fri, 4 Jun 2021 16:48:15 -0700 Subject: [PATCH] Allow user to limit version argument to --version --- CMakeLists.txt | 5 +++++ include/argparse/argparse.hpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dcb31a..6b60907 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,17 @@ cmake_minimum_required(VERSION 3.8) project(argparse VERSION 1.0.0 LANGUAGES CXX) option(ARGPARSE_BUILD_TESTS OFF) +option(ARGPARSE_LONG_VERSION_ARG_ONLY OFF) include(GNUInstallDirs) add_library(argparse INTERFACE) add_library(argparse::argparse ALIAS argparse) +if (ARGPARSE_LONG_VERSION_ARG_ONLY) + target_compile_definitions(argparse INTERFACE ARGPARSE_LONG_VERSION_ARG_ONLY=true) +endif () + target_compile_features(argparse INTERFACE cxx_std_17) target_include_directories(argparse INTERFACE $ diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 424731f..ad8d8be 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -815,7 +815,11 @@ public: std::string aVersion = "1.0") : mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) { add_argument("-h", "--help").help("shows help message and exits").nargs(0); +#ifndef ARGPARSE_LONG_VERSION_ARG_ONLY add_argument("-v", "--version") +#else + add_argument("--version") +#endif .help("prints version information and exits") .nargs(0); }