Skip to content

set_version_flag seems broken #1221

@delpinux

Description

@delpinux

Hi.

It seems that set_version_flag behavior changed recently.
Previously, even using required options, when using the version flag application just printed the version as expected and exited.
Now, returns an error and does not print version anymore.

I just tested with today's main branch a41ba814b3202aeb35f6ed36f0fde80402bf85cc.

Here is a simple reproducer.

#include <CLI/CLI.hpp>
#include <string>

int main(int argc, char*argv[]) {
  CLI::App app{"reproducer"};

  std::string filename;
  auto filename_option= app.add_option("filename", filename, "data file")
    ->check(CLI::ExistingFile)
    ->required();

  auto version_flag = app.set_version_flag("-v,--version", "0.0.1");

  try {
    app.parse(argc, argv);
  }
  catch (const CLI::ParseError& e) {
    std::exit(app.exit(e, std::cout, std::cerr));
  }

  return 0;
}

running it produces

$ ./a.out --version
filename is required
Run with --help for more information.

and adding a useless existing filename gives

$ ./a.out --version a_file
0.0.1

Thanks,
Stéphane.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions