Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set position of arguments in the help message #13

Open
victormihalache opened this issue Sep 15, 2021 · 0 comments
Open

Can't set position of arguments in the help message #13

victormihalache opened this issue Sep 15, 2021 · 0 comments

Comments

@victormihalache
Copy link

I was playing with this library and made the following in main.cpp:

#include <iostream>

#include <fstream>
#include <vector>

#include "argparse.h"

int main (int argc, const char * argv[])
{
  std::cout << "Hi" << std::endl;

  argparse::ArgumentParser parser ("test", "idkwhatthisdoes");
  parser.add_argument ()
    .names ({"-q", "--query"})
    .description ("Define search query for what to look for")
    .required (true)
    .position (0);
  parser.add_argument ()
    .names ({"-i", "--input-file"})
    .description ("Specifies the input file")
    .required (true)
    .position (1);
  parser.add_argument ()
    .names ({"-o", "--output-file"})
    .description ("Specifies the output file")
    .required (true)
    .position (2);
  parser.add_argument ()
    .names ({"-u", "--username"})
    .description ("Specifies the username to search. If empty username search will be ignored")
    .required (false);
  parser.enable_help ();

  auto err = parser.parse (argc, argv);
  if (err)
  {
    std::cout << err << std::endl;
    return -1;
  }

  if (parser.exists("help"))
  {
    parser.print_help();
    return 0;
  }

  if (parser.exists("q"))
  {
    std::cout << "woah query" << parser.get<std::string>("q") << std::endl;
    return 0;
  }

  return 0;
}

Running ./main -h gives me:

$ ./build/mtcs -h
Hi
Usage: test [q] [1] [i] [2] [o] [options...]
Options:
    -q, --query            Define search query for what to look for (Required)
    -i, --input-file       Specifies the input file (Required)
    -o, --output-file      Specifies the output file (Required)
    -u, --username         Specifies the username to search. If empty username search will be ignored
    -h, --help             Shows this page

But I expect:

$ ./build/mtcs -h
Hi
Usage: test [q] [i] [o] [options...]
Options:
    -q, --query            Define search query for what to look for (Required)
    -i, --input-file       Specifies the input file (Required)
    -o, --output-file      Specifies the output file (Required)
    -u, --username         Specifies the username to search. If empty username search will be ignored
    -h, --help             Shows this page

Why do numbers appear between arguments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant