question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a sub command appears to cause config file to be ignored

See original GitHub issue

Reproduce Bug

python source

import configargparse
def example():
    parser = configargparse.ArgumentParser(prog="test")
    parser.add_argument(
        '-e',
        '--environments',
        type=str,
        dest='environments',
        metavar='Environment',
        choices=['dev', 'test', 'beta', 'prod'],
        action='append',
        nargs='?',
        required=True,
        help="List of deployment environments to prepare"
    )
    parser.add_argument(
        '-s',
        '--solution_path',
        type=str,
        dest='solution_path',
        metavar='Solution Path',
        required=True,
        nargs='?',
        help='Path to the root of the application source files'
    )
    parser.add_argument(
        '-c',
        '--config',
        dest='my--config',
        is_config_file=True,
        nargs='?',
        help='Config file path'
    )
    command_subparsers = parser.add_subparsers(title='Commands', dest='command', required=True)
    command_subparsers.add_parser('help', help="Prints this screen")
    args = parser.parse_known_args()
    print(args)

if __name__ == '__main__':
    example()

my-config.conf source

environments = [test, beta]
solution_path = /var/PhotApp

command

$ python3 -m my-module -c ../my-config.conf help

output:

usage: test [-h] -e [Environment] -s [Solution Path] [-c [MY--CONFIG]]
            {help} ...
test: error: the following arguments are required: -e/--environments, -s/--solution_path

Bypass Bug

comment out these lines

    command_subparsers = parser.add_subparsers(title='Commands', dest='command', required=True)
    command_subparsers.add_parser('help', help="Prints this screen")

run w/ sub command

$ python3 -m my-module -c ../my-config.conf

output

(Namespace(environments=['test', 'beta'], solution_path='/var/PhotApp', **{'my--config': '../my-config.conf'}), [])

Questions

It seems to me that adding a subcommand breaks configuration parsing.

Can anyone show me why this isn’t a bug?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
Aetyluscommented, Jul 1, 2020

While the above solution does seem to work, this ends up necessitating multiple config files - one for the main parser, and then one for each of the subparsers - and multiple, unique arguments for the config file. This doesn’t seem ideal to me in that the config can’t all be read from one file. If any config file has arguments not related to its particular parser, you end up with

error: unrecognized arguments: [...]

At least for me, what would make most intuitive sense is that the config file for the main parser applies any argument values relevant to subparsers.

3reactions
moi90commented, May 16, 2021

I would expect that config file sections (which are currently ignored) correspond to subcommands.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I make Git ignore file mode (chmod) changes?
Try: git config core.fileMode false. From git-config(1): core.fileMode Tells Git if the executable bit of files in the working tree is to be...
Read more >
.gitignore file - ignoring files in Git | Atlassian Git Tutorial
Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working...
Read more >
An error occurred when sending commands to the program in ...
Method 1: Ignore DDE​​ To correct this setting, follow these steps: Select File > Options. Select Advanced, scroll down to the General section, ......
Read more >
git-add Documentation - Git
The git add command can be used to add ignored files with the -f (force) option. Please see git-commit[1] for alternative ways to...
Read more >
Ignoring Code - ESLint - Pluggable JavaScript Linter
You can ignore files in the following ways: Add ignorePatterns to a configuration file. Create a dedicated file that contains the ignore patterns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found