Skip to content

default_value / implicit_value incompatible with store_into #413

Description

@noajshu

Trying to make an inverted flag argument and use store_into. It does not seem to work as expected.

Minimum reproducing example:

#include <argparse/argparse.hpp>
int main(int argc, char* argv[]) {
  argparse::ArgumentParser program("cool binary");

  bool nicearg = false;
  program.add_argument("--deactivate")
      .help("Disable BFS-based detector ordering and use geometric orientation")
      .default_value(true)
      .implicit_value(false)
      .store_into(nicearg);

  try {
    program.parse_args(argc, argv);
  } catch (const std::exception& err) {
    std::cerr << err.what() << std::endl;
    std::cerr << program;
    return EXIT_FAILURE;
  }

  std::cout << "got nicearg = " << nicearg << std::endl;
}

Expected behavior: the nicearg should be true by default but false when the flag --deactivate is present. Actual behavior: nicearg is always true.

~/argparse-3.2$ clang++-19 -I include/  main.cc -o main
$ ./main
got nicearg = 1
$ ./main --deactivate
got nicearg = 1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions