ConfigArgParse icon indicating copy to clipboard operation
ConfigArgParse copied to clipboard

Hardcoded description text cannot be modified

Open fdw opened this issue 4 years ago • 9 comments

I have a short description text in my config, like this: parser = configargparse.ArgumentParser( description='Just one sentence to describe my utility'. Now I noticed that ConfigArgParse appends several sentences to this, completely drowning out my (purposely short) description. I cannot seem to find a switch to change this behavior. Neither can I append line breaks (\n) to make it easier to read.

Is there a way to configure this?

fdw avatar May 23 '20 08:05 fdw

I have the same issue...

dbrnz avatar Sep 04 '20 06:09 dbrnz

I'm not sure I understand the issue. If I run

test.py

import configargparse

p = configargparse.ArgumentParser(description='Just one sentence to describe my utility')
p.add_arg("test")
p.parse_args()

python3 test.py --help

It outputs

usage: test.py [-h] test

Just one sentence to describe my utility

positional arguments:
  test

optional arguments:
  -h, --help  show this help message and exit

which seems fine.

bw2 avatar Feb 14 '21 22:02 bw2

Please try:

import configargparse

p = configargparse.ArgumentParser(description='Just one sentence to describe my utility')
p.add('-c', '--my-config', required=True, is_config_file=True, help='config file path')
p.add('--genome', required=True, help='path to genome file')
p.parse_args()

I get:

usage: test.py [-h] -c MY_CONFIG --genome GENOME

Just one sentence to describe my utility Args that start with '--' (eg. --genome) can also be set in a config file (specified via -c).
Config file syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at https://goo.gl/R74nmi). If an arg is specified in
more than one place, then commandline values override config file values which override defaults.

optional arguments:
  -h, --help            show this help message and exit
  -c MY_CONFIG, --my-config MY_CONFIG
                        config file path
  --genome GENOME       path to genome file

dbrnz avatar Feb 15 '21 00:02 dbrnz

ok, how about adding an ArgParser constructor option to customize the config file-related help text - for example a config_global_help_message arg below https://github.com/bw2/ConfigArgParse/blob/master/configargparse.py#L387 and it would be set to None by default.

Then @ https://github.com/bw2/ConfigArgParse/blob/master/configargparse.py#L910-L924 if the value is None it would print the current message. If the value is not None, it overrides the defaults message. You could then set it to "".

bw2 avatar Feb 15 '21 14:02 bw2

That would solve my problem, yes :)

fdw avatar Feb 15 '21 16:02 fdw

Yes to a constructor option that would allow config file related text to be modified or suppressed.

Isn't there also a formatting issue? Shouldn't the above read:

Just one sentence to describe my utility

Args that start with '--' (eg. --genome) can also be set in a config file (specified via -c).
Config file syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at
https://goo.gl/R74nmi). If an arg is specified in more than one place, then commandline values
override config file values which override defaults.

In fact, would things not read better if the config file text was at the end of the help output? That is:

usage: test.py [-h] -c MY_CONFIG --genome GENOME

Just one sentence to describe my utility

optional arguments:
  -h, --help            show this help message and exit
  -c MY_CONFIG, --my-config MY_CONFIG
                        config file path
  --genome GENOME       path to genome file

Args that start with '--' (eg. --genome) can also be set in a config file (specified via -c).
Config file syntax allows: key=value, flag=true, stuff=[a,b,c] (for details, see syntax at
https://goo.gl/R74nmi). If an arg is specified in more than one place, then commandline values
override config file values which override defaults.

dbrnz avatar Feb 15 '21 19:02 dbrnz

I like the idea of moving the text to the end of the help output. Would either of you guys be willing to submit a PR for this?

bw2 avatar Feb 16 '21 00:02 bw2

See PR #208.

dbrnz avatar Feb 16 '21 03:02 dbrnz

@dbrnz 's PR is now merged. Will wait a couple days to see if PR #210 gets fixed, then make a new release.

bw2 avatar Feb 18 '21 02:02 bw2