Skip to content

NargsValueFlag does not work with separator? #192

Description

@stgrzeszczak

I'm working on a tool which does not set ArgumentSeparations options, but the users are accustomed to using = for arguments.
We've recently added a new NargsValueFlag flag with the expectation that it would work with both a = and a whitespace for the list of arguments, but it seems not to be the case. Here's a minimal example:

$ ./a.out --inputs 1 2 3
got this many inputs: 3

$ ./a.out --inputs=1 2 3
Passed in argument, but no positional arguments were ready to receive it: 2
  ./a.out {OPTIONS}

    NargsValueFlag test program.

  OPTIONS:

      --inputs=[inputs]                 use this flag to provide inputs

Code for this example:

#include "args/args.hxx"
#include <iostream>
#include <string>
#include <vector>

int main (int argc, char **argv){
    args::ArgumentParser parser("NargsValueFlag test program.", "");

    auto multiple = args::NargsValueFlag<std::string>(parser, "inputs",
                    "use this flag to provide inputs", args::Matcher({"inputs"}), args::Nargs(1, 10));
    try
    {
        parser.ParseCLI(argc, argv);
    }
    catch (args::Help)
    {
        std::cout << parser;
        return 0;
    }
    catch (args::ParseError e)
    {
        std::cerr << e.what() << std::endl;
        std::cerr << parser;
        return 1;
    }
    catch (args::ValidationError e)
    {
        std::cerr << e.what() << std::endl;
        std::cerr << parser;
        return 1;
    }

    if (multiple) { std::cout << "got this many inputs: " << args::get(multiple).size() << std::endl; }

    return 0;
}

Is this the expected behavior? Is there any way to force NargsValueFlag to accept multiple values when a separator is used?

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