Questions tagged [subparsers]

Use this tag for questions related to a subparser, an entity that supports the creation of sub-commands.

Many programs split up their functionality into a number of sub-commands, for example, the svn program can invoke sub-commands like svn checkout, svn update, and svn commit. Splitting up functionality this way can be a particularly good idea when a program performs several different functions which require different kinds of command-line arguments. supports the creation of such sub-commands.

Source: Subparsers

While most questions of this tag are related to Python, Django and C# are also welcomed.

45 questions
0
votes
1 answer

How to use subparses for optional positional arguments?

I have just started working with argprase, and have the following example main.py which has optional arguments import os import numpy import argparse def main(): parser = argparse.ArgumentParser() parser.add_argument('-C','--Chk',type=str,…
newstudent
  • 402
  • 6
  • 19
0
votes
1 answer

python argparse two subparsers are basically same.. almost

is it possible to extend subparsers new names without implementing all of their parameters twice? I have a program, let's call it pgmm which has a sub function create. This create function needs a config file somewhere. To prevent looking for this,…
TecDroiD
  • 113
  • 1
  • 6
0
votes
1 answer

Argument Parser Problem: Optional argument with then 3 required subarguments

I am writing an argument parser for a program. The current parser behaves like: Simulate Roboy in MuJoCo. positional arguments: P Proportional Gain I Derivational Gain D Integral Gain …
0
votes
0 answers

How do you create subcommands with argparse using subparsers when the subcommands have different arguments?

There are similar solutions here, but they either deal with much older versions of python, or deal only with parsers but not subparsers. I am writing a program with a simple command line interface. I would like the script to have subcommands. The…
Derek1st
  • 63
  • 6
0
votes
2 answers

Select limited arguments from Parent Parser

I have been working with Argparse for a while and here's the StackOverflow Answer to the question that I was having. Add arguments to multiple subparsers This answer is not completely solving my problem. Here's the edited code borrowed from the…
Jayesh Padhiar
  • 73
  • 1
  • 1
  • 6
0
votes
0 answers

python cmd2 multiarg parser

I have 4 arguments eg: a,b,c,d. Users have the option to enter a or b or c or d else a or c else enter 'a' only or 'd' only like that follow all probability. for that how to write the argument parser. subscription_parser =…
0
votes
1 answer

Argparse optional arguments with multilevel parser/subparser

I have a set of parsers and subparsers to build a production or development system. If the user picks production, he can add options and all is well. If he pics development, he can enter an architecture and then enter build options. This is where it…
Alan
  • 53
  • 7
0
votes
1 answer

Python argparse with Generic Subparser Commands

I have a python script that I want to use as a wrapper for another commandline tool. I want to intercept any subcommands that I have defined, but pass through all other subcommands and arguments. I have tried using a subparser, which seems ideal,…
Joseph Glover
  • 330
  • 3
  • 11
0
votes
1 answer

Argparse with subparsers not working and I cannot figure it out

I am using argparse with subparsers to do different actions. Each action has slightly different arguments. I have set it up as the documentations instructs, with one action in subparser (parser_2) and the other subparser (parser_3) when i do help…
G J
  • 33
  • 6
0
votes
0 answers

Dividing large program into subcommands with argparse

I want to use six subcommands (using subparsers from the argparse library) to divide my large program into smaller independent programs, and be able to run them individually. In other words, I envision running six commands from the command line one…
John Smith
  • 393
  • 1
  • 6
  • 17
0
votes
1 answer

Argparse using function from another file within that file

I have two classes: OptionParser Application stored in separate files (option_parser.py and application.py). The former defines how command line input should be handled. The latter imports the former, reads the user input, and carries on with the…
user1766396
  • 33
  • 1
  • 5
0
votes
1 answer

Python argparse subparser valid usage?

I am planing to write a command using the argparse library, this is my command structure: $ python cvs.py -d my_adress local diff -r xyz -N -d details Here, the local has multiple command grouped to it such as local commit, local add etc. E.g. [-d…
Shivendra Mishra
  • 638
  • 4
  • 25
-1
votes
2 answers

How to use sub-commands along with optional positional arguments in argparse

Below scripts prints an output as well as opens a webpage based on command line arguments. #main.py import os, numpy import argparse import webbrowser new=2 def main(): parser = argparse.ArgumentParser() …
newstudent
  • 402
  • 6
  • 19
-1
votes
1 answer

argparse solution requested for commands and subcommands with subcommands

Hopefully this will translate into an elegant solution, but i am unable to figure it out myself. I have been reading huge amounts of examples and explanations but I cant seem to get it to work. I am writing a program that needs the following…
FrankIJ
  • 1,987
  • 1
  • 10
  • 11
-1
votes
1 answer

How to perform an argparse subparse for [-A[-b value]] in Python

I want to recreate [-A [-b value]] where in command would look like this: test.py -A -b 123 Seems really simple but I can't get it right. My latest attempt has been: byte = subparser.add_parser("-A") byte.add_argument("-b", type=int)
Panda
  • 51
  • 1
  • 8
1 2
3