Skip to content

Could not convert: integer option passed as a string with an extra space after the value #1094

@aphecetche

Description

@aphecetche

A very simple example (using version 2.4.2) "fails" when called with -i "42 " (note the extra space at the end of the string), but works fine for e.g. -i " 42" (space before the integer) (and of course for the more natural way of calling it directly with an integer, e.g. -i 42

Is that a feature or a bug ? Knowing that e.g. std::stoi convert both " 42" and "42 " just fine, I'd call it a bug, but there might be something obvious I'm missing here ?

see e.g. https://godbolt.org/z/jad4MfsKP to run it

#include <iostream>
#include "CLI/CLI.hpp"

int main(int argc, char** argv)
{
  int value{0};

  CLI::App app{"basic cli example"};

  app.option_defaults()->always_capture_default();

  app.add_option("-i", value);

  try {
    app.parse(argc, argv);
  }
  catch (const CLI::ParseError& error) {
    std::cout << "CLI11 " << error.what() << "\n";
    return app.exit(error);
  }

  std::cout << "value=" << value << "\n";
}

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