Linked Questions

12 questions linked to/from Argparse with required subparser
0 votes
1 answer
465 views

I would like to make sure at least one of the sub commands is selected. But there is no required option for add_subparsers() how can I enforce at least one subparser is selected? Currently I did this ...
Wang's user avatar
  • 8,446
40 votes
4 answers
20k views

With python's argparse, how do I make a subcommand a required argument? I want to do this because I want argparse to error out if a subcommand is not specified. I override the error method to print ...
PonyEars's user avatar
  • 2,274
18 votes
6 answers
18k views

Intro I'm trouble for a school project. I'm making a testsuit and i'm needing bot a configuration generation interface and a test runner. For that i used the library argparse and two subparsers cgi ...
Biboozz's user avatar
  • 1,096
17 votes
1 answer
6k views

The following code, using argparse's subparsers, fails on Python 3 but runs as expected in Python 2. After comparing the docs, I still can't tell why. #!/usr/bin/env python from __future__ import ...
2 votes
2 answers
8k views

I'm using Python 2.7 and I'm trying to accomplish a shell like behavior using argparse. My issue, in general, that I cannot seem to find a way, in Python 2.7, to use argparse's subparsers as optional. ...
0 votes
1 answer
5k views

I have below python script which if I run with Python 2.7.16 version then I get an error but if I run with Python 3 version then it works fine. Below is my code: from argparse import ArgumentParser ...
0 votes
1 answer
2k views

I have a utility which allows a user to read their ~/.aws/credentials file and export environment variables. Currently, the CLI interface looks like this: usage: aws-env [-h] [-n] profile Extract ...
1 vote
1 answer
2k views

I'm very new to this module so please bear with me. I have the following code: reader.py import argparse parent_parser = argparse.ArgumentParser(description="Read text files.") parent_parser....
0 votes
1 answer
901 views

Using python version 3.9.5 I have a problem with the following code snippet: import argparse parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(required=False) sub_parser = ...
2 votes
1 answer
2k views

I haven't used argparse in 10 years, but I understand it and what I have below does work as I want it to work... but this is going to get a lot more complicated as I continue adding commands, parsers ...
gunslingor's user avatar
  • 1,535
2 votes
1 answer
142 views

In my example below, I am trying to setup the following command line scenarios: $ myapp.py flowers [-h] $ myapp.py flowers plants [-h] $ myapp.py flowers plants add [-h] The actual outcomes are: $ ...
101010's user avatar
  • 16k
0 votes
0 answers
37 views

The commandline interface that I want is something like this: my-executable command REQUIRED_ARG # or my-executable command subcommand [--foo] [--bar] So, I don't want REQUIRED_ARG to be required (...