0

I have made a python code, which needs some arguments to be passed:

parser = argparse.ArgumentParser(description='RAPIT', formatter_class=RawTextHelpFormatter)
parser.add_argument("-f", "--fastq", help="Fastq_file location", required=True)
parser.add_argument("-w", "--workdir", default=cwd, help="Provide Working directory")
parser.add_argument("-c", "--cleanRUN", action="store_true", help="Delete SAM files")
parser.add_argument("-g", "--gtf", default="", help="GTF file location")
parser.add_argument("-s", "--starIndex", default="", help="STAR indexed genome location")
if len(sys.argv) == 1:
    parser.print_help(sys.stderr)
    sys.exit(1)
args = parser.parse_args()

When I call the main.py in a linux system I get this help:

usage: main.py -f FASTQ [-w WORKDIR] [-c] [-g GTF] [-s STARINDEX]

RAPIT

options:
  -f FASTQ, --fastq FASTQ
                        Fastq_file location
  -w WORKDIR, --workdir WORKDIR
                        Provide Working directory
  -c, --cleanRUN        Delete SAM files
  -g GTF, --gtf GTF     GTF file location
  -s STARINDEX, --starIndex STARINDEX
                        STAR indexed genome location

This is not nice at all, and I wold like to know, why is for example "FASTQ" inserted between -f and --fastq?

Ideally I would like it to look like this:

-f, --fastq Fastq_file location
-w, --workdir Provide Working directory
etc

Can you please help me, what could be the problem? Thanks!

pahi
  • 95
  • 5
  • 1
    Just `-f` implies it's a boolean flag, not an argument which takes a value after it. – deceze Apr 14 '23 at 13:38
  • 3
    Your suggested output is all but ideal, it does not show the user on first sight, which flags require an argument (-f, -w) and which flags don't (-c). – treuss Apr 14 '23 at 13:40
  • 1
    The `usage` line is meant to provide a concise guide. The help lines elaborate on what can be done with each argument. The same `FASTQ` 'metavar' is used in both. Others have argued that the help lines could be more concise (see other SO), but this is the style that argparse has used for the past dozen plus years. Feel free to subclass the `HelpFormater` and change some methods for your own use. – hpaulj Apr 14 '23 at 14:30
  • 1
    I added duplicated from 9 years ago about changing the help formmater. – hpaulj Apr 14 '23 at 15:24

0 Answers0