Skip to content

Commit

Permalink
Merge pull request #103 from kfsone/optional-v
Browse files Browse the repository at this point in the history
Allow user to limit version argument to --version
  • Loading branch information
p-ranav authored Jun 5, 2021
2 parents 1344889 + 38b1b81 commit 64dd67c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand Down
4 changes: 4 additions & 0 deletions include/argparse/argparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,11 @@ class ArgumentParser {
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);
}
Expand Down

0 comments on commit 64dd67c

Please sign in to comment.