Questions tagged [subcommand]

Use this tag for questions related to subcommands, i.e. commands inside a routine.

Subcommands make it possible for you to group related command line functionality under one root command.

Examples of subcommands are install in apt-get install and push in git push.

Users tend to use this tag for questions related to existing subcommands, or subcommands that are an artifact of the users itselves. Last but not least, questions that handle subcommand arguments, for example in a Python program, are also suitable for this tag.

38 questions
46
votes
10 answers

Default sub-command, or handling no sub-command with argparse

How can I have a default sub-command, or handle the case where no sub-command is given using argparse? import argparse a = argparse.ArgumentParser() b = a.add_subparsers() b.add_parser('hi') a.parse_args() Here I'd like a command to be selected,…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
21
votes
7 answers

argparse optional subparser (for --version)

I have the following code (using Python 2.7): # shared command line options, like --version or --verbose parser_shared = argparse.ArgumentParser(add_help=False) parser_shared.add_argument('--version', action='store_true') # the main parser,…
miku
  • 181,842
  • 47
  • 306
  • 310
11
votes
4 answers

Python argparse positional arguments and sub-commands

I'm working with argparse and am trying to mix sub-commands and positional arguments, and the following issue came up. This code runs fine: import argparse parser = argparse.ArgumentParser() subparsers =…
user880248
11
votes
2 answers

How to handle CLI subcommands with argparse

I need to implement a command line interface in which the program accepts subcommands. For example, if the program is called “foo”, the CLI would look like foo cmd1 foo cmd2 foo cmd3 cmd1 and cmd3 must be used with at…
Enea
  • 113
  • 1
  • 4
10
votes
4 answers

How should I implement "nested" subcommands in Python?

Implementing "nested" subcommands in Python with cmdln. I'm not sure I'm using the right terminology here. I'm trying to implement a commandline tool using cmdln that allows for "nested" subcommands. Here is a real world example: git svn…
tima
  • 413
  • 1
  • 5
  • 11
10
votes
4 answers

Java CLI Parser

I know that this question has been asked already, but I'm looking for Java cli parser with a specific functionality. I want it to be able to define command line tree, thus using subcommands (and more than one level depth). Thus i can have 3-4 level…
Sophie
  • 1,580
  • 3
  • 16
  • 20
9
votes
5 answers

Python: argument parser that handles global options to sub-commands properly

argparse fails at dealing with sub-commands receiving global options: import argparse p = argparse.ArgumentParser() p.add_argument('--arg', action='store_true') s = p.add_subparsers() s.add_parser('test') will have p.parse_args('--arg…
user78110
5
votes
3 answers

How to alias a tag in Git?

I have a Git command alias to checkout the latest tag from a repository: ~/.gitconfig: checkout-latest = !git checkout $(git describe --tags `git rev-list --tags --max-count=1`) So I can use it in properly tagged repositories like this: $ git…
Bengt
  • 14,011
  • 7
  • 48
  • 66
5
votes
1 answer

Sub-commands with bash

Is it possible to implement sub-commands for bash scripts. I have something like this in mind: http://docs.python.org/dev/library/argparse.html#sub-commands
LavaScornedOven
  • 737
  • 1
  • 11
  • 23
4
votes
2 answers

Multiple invocation of the same subcommand in a single command line

I'm trying to figure out how to use argparser to do the following: $ python test.py executeBuild --name foobar1 executeBuild --name foobar2 .... getBuild itself is a sub-command. My goal is to have the script have the capability to chain a series…
Avaclon
  • 163
  • 6
3
votes
1 answer

Picocli: how to make subcommands required

I have a command with subcommands. In my application I want it mandatory for the user to specify a subcommand. How should I do this? (See also https://github.com/remkop/picocli/issues/529)
Remko Popma
  • 35,130
  • 11
  • 92
  • 114
3
votes
2 answers

Parse multiple subcommands in python simultaneously or other way to group parsed arguments

I am converting Bash shell installer utility to Python 2.7 and need to implement complex CLI so I am able to parse tens of parameters (potentially up to ~150). These are names of Puppet class variables in addition to a dozen of generic deployment…
Elvinas
  • 81
  • 2
  • 7
2
votes
1 answer

How to install the command "cargo set-version"?

I'm trying to run a script that requires the cargo subcommand cargo set-version --workspace --bump="${2:-}". How do I install it? Google results only returned cargo install set-cargo-version but that is actually a different crate, not the one I need…
Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
2
votes
1 answer

Tab autocomplete and simple implementation of subcommands in python cmd module?

Is it possible to add tab autocomplete to subcommands in the python Cmd class in the cmd module? Say I am running my command loop, and I wanted to have a command called add, where I can then have a selection of animal names, like add horse, or add…
contrapsych
  • 1,919
  • 4
  • 29
  • 44
2
votes
0 answers

How to execute sub commands while executing one main command through build.xml

I have been trying to execute a list of commands through the build.xml as below
Jayaram
  • 33
  • 1
  • 2
1
2 3