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.

Allow repeatable subcommands?

See original GitHub issue

I came here looking for a solution for a problem similar to #358 - the need for a syntax for lists of multi-field entries - but had a different solution in mind. These solutions are not mutually exclusive, so I elected to open a new ticket for it.

My idea is to have repeatable subcommands. So - if we take the example from #358 - print will be the main command and have, say, file as a subcommand. We will write it like so:

print --paper A4 \
    file A.pdf \
    file B.pdf --count 3 \
    file C.pdf --count 3 --rotate left \
    file D.pdf \
    file E.pdf --rotate right

This will create 6 CommandLine objects:

  • PrintCommand(paper = “A4”)
  • FileCommand(name = “A.pdf”, count = <default>, rotate = <default>)
  • FileCommand(name = “B.pdf”, count = 3, rotate = <default>)
  • FileCommand(name = “C.pdf”, count = 3, rotate = “left”)
  • FileCommand(name = “D.pdf”, count = <default>, rotate = <default>)
  • FileCommand(name = “E.pdf”, count = <default>, rotate = “right”)

A bit more verbose than @kravemir’s original syntax (since you need to specify the options for each file) but much more readable IMHO.

I tried to do it by making file a subcommand of itself:

CommandLine printCommand = new CommandLine(new PrintCommand());
CommandLine fileCommand = new CommandLine(new FileCommand());
printCommand.addSubcommand(fileCommand);
fileCommand.addSubcommand(fileCommand);

And it did parse that command line - but it was always using the same FileCommand object so I only got E.pdf’s parameters. Maybe if a CommandLine could receive a factory for objects, and construct a new one for each subcommand it parses?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:30 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
remkopcommented, Feb 12, 2020

@idanarye, @kravemir, @hanslovsky, @lakemove, All,

picocli 4.2.0 has been released, including this feature. Enjoy!

2reactions
idanaryecommented, Feb 1, 2020

I’m already abusing them enough as is, so I’m not going to request any farther complications.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clikt - Common Options With Subcommands
There are several ways to structure your commands to avoid repeating the option ... This allows you to specify all options after the...
Read more >
picocli - a mighty tiny command line interface
Enable Consuming Option Names or Subcommands. Picocli 4.7.0 introduces two parser configuration options to change this behaviour: CommandLine:: ...
Read more >
How to Use /execute (All Subcommands) (Command Tutorial ...
A tutorial on how to use the /execute command, and all its subcommands, to control how, where, and if a command is run....
Read more >
REPEATING DATA (PSPP) - GNU.org
When data groups are continued from line to line, it is easy for cases to get out of sync through careless hand editing....
Read more >
ftp Command - IBM
The ftp command interpreter, which handles all subcommands entered at the ftp> ... These facilities help simplify repetitive tasks and allow you to...
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