argparse icon indicating copy to clipboard operation
argparse copied to clipboard

Can't set position of arguments in the help message

Open victormihalache opened this issue 3 years ago • 0 comments

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?

victormihalache avatar Sep 15 '21 08:09 victormihalache