Skip to content

Releases: p-ranav/argparse

argparse

17 Jul 23:58
Compare
Choose a tag to compare
  • Bug fix on choices. #310
  • Fix for C++23 standard library module usage. #326
  • Make clang -fsanitize=unsigned-integer-overflow happy #328
  • Add ways to substitute strtof/strtod/strtold with custom functions #329
  • Add a ArgumentParser::add_hidden_alias_for() method #330
  • Add Argument::store_into() functions #331
  • Add a dry_run argument to Argument::consume(), and change ArgumentParser private section to protected #332
  • Several bug fixes in usage, and improvement in usage and help #334
  • Add a Argument::hidden() method to prevent an argument from appearing in usage or help #336
  • Add Argument::store_into(std::vector<int> &var) method #343
  • Fix parsing of a program that accepts a positional argument with 1:* cardinality followed by another positional argument with 1:1 #344
  • Store ints #346
  • Add Argument::store_into(std::set<int||string> &var) method #348
  • Add Bazel support #352
  • do_from_chars(): initialize variable to fix Coverity Scan warning #353
  • Module improvement. #357
  • parse_args(): work around GCC 12 warning bug. #359
  • Add argument name after 'Too few arguments' error #360
  • Correct Parent Parser errors in README.md #361
  • Allow to install when argparse is a subproject #364

argparse

06 Nov 01:51
af442b4
Compare
Choose a tag to compare

Features / Enhancements

  • Added support for mutually_exclusive_arguments #301, README
  • Added C++20 module #290
  • Added built-in choices argument support. #277, README
  • Added support for binary notation, e.g., 0b101 #306
  • Added is_subcommand_used overload that accepts a subcommand parser #233
  • Added exit_on_default_arguments parameter to ArgumentParser #264
  • A (hide-from-help) suppress flag for subcommands #273
  • Allowed check to see if ArgumentParser has parsed values #218
  • Implemented column-aligned multi-line help message for arguments #259

Fixes

  • Marked ArgumentParser copy and move constructors as deleted #304
  • Fixed error text when multiple positional arguments are expected #209
  • Fixed std::string_view being identified as a container #229
  • Fixed crash with char[] default values #253
  • Resolves a std::numeric_limits<std::size_t>::max)()} error #263
  • Fixed issue #248: Align multiline help messages #268
  • Various maintenance fixes #254

Other

  • Added clang-tidy to PRs #215
  • No install when used as third party #231
  • Install cmake export file in CMAKE_INSTALL_DIR #255
  • CMakefile: Use -Wpedantic, -Werror and -Wextra for compilation in gcc. Fixed warnings #292
  • Updates to README cmake FetchContent section #293
  • More descriptive parse_number errors #297

argparse

22 Sep 02:28
Compare
Choose a tag to compare

Thanks @ndevenish and @skrobinson

  • Added support for parse_known_args #201
  • Added -Wsign-conversion to the tests build and removed implicit conversion warnings #202
  • Allow --option=value form of arguments #203
  • Added -Wshadow and -Wconversion to CXX_FLAGS and fixed warnings #204
  • Added prefix_chars and assign_chars support for better option-value syntax #205
  • Improved help, metavar, subcommands, and samples #206

argparse

21 Sep 04:24
Compare
Choose a tag to compare

Subcommands

Many programs split up their functionality into a number of sub-commands, for example, the git program can invoke sub-commands like git checkout, git add, and git commit. Splitting up functionality this way can be a particularly good idea when a program performs several different functions which require different kinds of command-line arguments. ArgumentParser now supports the creation of such sub-commands with add_subparser().

#include <argparse/argparse.hpp>

int main(int argc, char *argv[]) {
  argparse::ArgumentParser program("git");

  // git add subparser
  argparse::ArgumentParser add_command("add");
  add_command.add_argument("files")
    .help("Files to add content from. Fileglobs (e.g.  *.c) can be given to add all matching files.")
    .remaining();

  // git commit subparser
  argparse::ArgumentParser commit_command("commit");
  commit_command.add_argument("-a", "--all")
    .help("Tell the command to automatically stage files that have been modified and deleted.")
    .default_value(false)
    .implicit_value(true);

  commit_command.add_argument("-m", "--message")
    .help("Use the given <msg> as the commit message.");

  // git cat-file subparser
  argparse::ArgumentParser catfile_command("cat-file");
  catfile_command.add_argument("-t")
    .help("Instead of the content, show the object type identified by <object>.");

  catfile_command.add_argument("-p")
    .help("Pretty-print the contents of <object> based on its type.");

  // git submodule subparser
  argparse::ArgumentParser submodule_command("submodule");
  argparse::ArgumentParser submodule_update_command("update");
  submodule_update_command.add_argument("--init")
    .default_value(false)
    .implicit_value(true);
  submodule_update_command.add_argument("--recursive")
    .default_value(false)
    .implicit_value(true);
  submodule_command.add_subparser(submodule_update_command);

  // Add the subcommands to the parent parser
  program.add_subparser(add_command);
  program.add_subparser(commit_command);
  program.add_subparser(catfile_command);
  program.add_subparser(submodule_command);

  // Parse args
  try {
    program.parse_args(argc, argv);
  }
  catch (const std::runtime_error& err) {
    std::cerr << err.what() << std::endl;
    std::cerr << program;
    std::exit(1);
  }

  // Use arguments
}
foo@bar:/home/dev/$ ./git --help
Usage: git [options] <command> [<args>]

Optional arguments:
-h --help    	shows help message and exits [default: false]
-v --version 	prints version information and exits [default: false]

Subcommands:
add          	Add file contents to the index
cat-file     	Provide content or type and size information for repository objects
commit       	Record changes to the repository
submodule    	Initialize, update or inspect submodules

foo@bar:/home/dev/$ ./git add --help
Usage: git add [options] files 

Add file contents to the index

Positional arguments:
files        	Files to add content from. Fileglobs (e.g.  *.c) can be given to add all matching files.

Optional arguments:
-h --help    	shows help message and exits [default: false]
-v --version 	prints version information and exits [default: false]

foo@bar:/home/dev/$ ./git submodule --help
Usage: git submodule [options] <command> [<args>]

Initialize, update or inspect submodules

Optional arguments:
-h --help    	shows help message and exits [default: false]
-v --version 	prints version information and exits [default: false]

Subcommands:
update       	Update the registered submodules to match what the superproject expects

When a help message is requested from a subparser, only the help for that particular parser will be printed. The help message will not include parent parser or sibling parser messages.

Additionally, every parser has a .is_subcommand_used("<command_name>") member function to check if a subcommand was used.

You can find relevant unit tests here.

argparse

18 Sep 14:18
Compare
Choose a tag to compare
  • Added empty line above epilog #186
  • Update CI hosts and fix clang-cl build #189
  • Remove unnecessary back_inserter #191
  • Use references for any_cast #192

argparse

22 Jun 18:03
Compare
Choose a tag to compare

Merged pull request #125 - Improve nargs

Thanks @hokacci

You can now make a variable length list of arguments with the .nargs.
Below are some examples.

program.add_argument("--input_files")
  .nargs(1, 3);  // This accepts 1 to 3 arguments.

Some useful patterns are defined like "?", "*", "+" of argparse in Python.

program.add_argument("--input_files")
  .nargs(argparse::nargs_pattern::any);  // "*" in Python. This accepts any number of arguments including 0.
program.add_argument("--input_files")
  .nargs(argparse::nargs_pattern::at_least_one);  // "+" in Python. This accepts one or more number of arguments.
program.add_argument("--input_files")
  .nargs(argparse::nargs_pattern::optional);  // "?" in Python. This accepts an argument optionally.

argparse

27 May 12:31
234f0cd
Compare
Choose a tag to compare
  • Add missing <utility> include 95d4850

argparse

20 Apr 13:48
Compare
Choose a tag to compare
  • Fixed regression in version printing 3b89546
  • Updated doctest version from v2.3.5 to v2.4.8 f56aec3
  • Fixed unused argument warnings 5c5c55b

argparse

02 Apr 00:08
Compare
Choose a tag to compare
  • Improve thrown message in case of invalid argument - Now message contains information which argument is the source of error. It's easier to spot typo/understand which part of more complex command is the source of problem. 87afaba
  • Update cmake_minimum_required to 3.12.4
  • Update "Printing Help" documentation 5cceb98
  • Updated README examples from exit() to std::exit() 8772b37
  • Code cleanup - data structure names, initialization etc.

argparse

14 Sep 14:32
b0cb28a
Compare
Choose a tag to compare
  • Simplify parsing numeric arguments with .scan #65
  • Get arguments in optional with .present() #68
  • Simplify a few internals #71
  • Add the option to add text before and after help output #72
  • Avoid use of cmd.exe in Travis #77
  • Fix incorrect message when mUsedName is empty #79
  • Make ArgumentParser::add_*() functions working on the parser itself chainable #82
  • CMakeLists.txt : add export #86
  • Fix help if required and def-value. Fixes #89. #90
  • Show default value for arg in help message #92
  • nicer usage text for required arg #93
  • Qualify iterator functions #97
  • misc clean ups #98
  • Add Argument.append method to allow repeated argument use #99
  • Add ArgumentParser.is_used to discern user-supplied values from defaults #100
  • Allow user to limit version argument to --version #103
  • Added packaging using CPack and generation of pkg-config files. #107
  • Const-correct ArgumentParser #108
  • Fix std::min conflict with min/max definitions from windows.h #109
  • Replace size_t to std::size_t. #110
  • Some cleanup in CPack packaging #115
  • Document and use Argument.scan where possible #121