This HowTo shows you how to write an argument parser with subcommand like git push
using SeqAn.
Difficulty | Easy |
---|---|
Duration | 15 min |
Prerequisite tutorials | Parsing command line arguments with SeqAn |
Recommended reading |
A common use case for command line tools, e.g. git
, is to have multiple subcommands, e.g. git fetch
or git push
. Each subcommand has its own set of options and its own help page. This HowTo explains how this can be done with the seqan3::argument_parser and serves as a copy'n'paste source. If you are new to SeqAn, we recommend to do the basic argument parser tutorial before you read further.
In order to keep parsing with subcommands straightforward and simple, the seqan3::argument_parser provides an advanced interface that internally takes care of the correct input parsing.
You simply need to specify the names of the subcommands when constructing your top-level argument parser:
./myfasta_parser --filext fasta fasta ...
).After calling seqan3::argument_parser::parse() on your top-level parser, you can then access the sub-parser via the function seqan3::argument_parser::get_sub_parser():
The sub-parser's seqan3::argument_parser::info::app_name will be set to the user chosen sub command. For example, if the user calls
then the sub-parser will be named mygit-push
and will be instantiated with all arguments followed by the keyword push
which in this case triggers printing the help page (-h
).
That's it. Here is a full example of a subcommand argument parser you can try and adjust to your needs: