Adding a sub command appears to cause config file to be ignored
See original GitHub issueReproduce 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:
- Created 5 years ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.
I would expect that config file sections (which are currently ignored) correspond to subcommands.