Allow user to limit version argument to --version

This commit is contained in:
Oliver 'kfsone' Smith 2021-06-04 16:48:15 -07:00
parent 1344889acf
commit 38b1b8114e
2 changed files with 9 additions and 0 deletions

View File

@ -1,12 +1,17 @@
cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
project(argparse VERSION 1.0.0 LANGUAGES CXX) project(argparse VERSION 1.0.0 LANGUAGES CXX)
option(ARGPARSE_BUILD_TESTS OFF) option(ARGPARSE_BUILD_TESTS OFF)
option(ARGPARSE_LONG_VERSION_ARG_ONLY OFF)
include(GNUInstallDirs) include(GNUInstallDirs)
add_library(argparse INTERFACE) add_library(argparse INTERFACE)
add_library(argparse::argparse ALIAS argparse) 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_compile_features(argparse INTERFACE cxx_std_17)
target_include_directories(argparse INTERFACE target_include_directories(argparse INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>

View File

@ -815,7 +815,11 @@ public:
std::string aVersion = "1.0") std::string aVersion = "1.0")
: mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) { : mProgramName(std::move(aProgramName)), mVersion(std::move(aVersion)) {
add_argument("-h", "--help").help("shows help message and exits").nargs(0); add_argument("-h", "--help").help("shows help message and exits").nargs(0);
#ifndef ARGPARSE_LONG_VERSION_ARG_ONLY
add_argument("-v", "--version") add_argument("-v", "--version")
#else
add_argument("--version")
#endif
.help("prints version information and exits") .help("prints version information and exits")
.nargs(0); .nargs(0);
} }