[Seqan-dev] ArgParseArgument list allowing zero or more items?
- From: Bernard James Pope <bjpope@unimelb.edu.au>
- To: "seqan-dev@lists.fu-berlin.de" <seqan-dev@lists.fu-berlin.de>
- Date: Sun, 10 Jul 2016 06:35:17 +0000
- Authentication-results: spf=pass (sender IP is 128.250.6.61) smtp.mailfrom=unimelb.edu.au; lists.fu-berlin.de; dkim=none (message not signed) header.d=none;lists.fu-berlin.de; dmarc=pass action=none header.from=unimelb.edu.au;
- Reply-to: SeqAn Development <seqan-dev@lists.fu-berlin.de>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
- Subject: [Seqan-dev] ArgParseArgument list allowing zero or more items?
Hi SEQAN devs,
I'm writing a program which accepts zero or more FASTA files on the command line, as positional arguments.
If zero files are specified, then it will default to reading from standard input.
I want to write a Seqan argument parser to capture this behaviour. However, I seem stuck with a solution that requires at least one file to be specified.
Here's a sketch of what I have:
ArgumentParser parser(PROGRAM_NAME);
addOption(parser, ArgParseOption("f", "foo", "Silly example", ArgParseArgument::INTEGER, "INT"));
addArgument(parser, ArgParseArgument(ArgParseArgument::STRING, "FASTA_FILE", true));
ArgumentParser::ParseResult res = parse(parser, argc, argv);
Notice that isListArgument is set to true.
However, when I run my program, and specify zero positional arguments (but some other option arguments), e.g.
$ myprogram -foo 0
I get the error:
Not enough arguments were provided.
Is there a way to achieve what I want to do?
I thought I might be able to default the ArgParseArgument to be an empty vector somehow, but couldn't get that to work.
If anyone has used the Python ArgumentParser before, the behaviour I want to emulate is the ability to specify nargs='*'
Cheers,
Bernie