Replies: 1 comment 1 reply
-
If you want to pass Java objects via the memory of the Java runtime, you could set some static value and let each command read that static value for further processing. (The Java equivalent of a global variable.) An alternative is to serialize the object to a file and pass the path to that file as a command line argument. That's all I can think of now. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What's the best way to dynamically call other commands from a Picocli command implementation?
Suppose I have a sub-command named
run
that reads a YAML file containing instructions like the following:When encountering the
cmd
property above, I'd like to execute the given sub-command and retrieve it's output and exit code.The following pseudocode seems to work for basic invocation (not explicitly handling command output yet), but not sure whether this is the best approach and whether this may cause any side-effects.
Ideally, I'd also like to have a generic mechanism to allow the sub-commands being run to pass data back to the
YamlRunner
through Java method calls. Is there any way to pass some Java object to the command being executed, for example using some execution context that can be retrieved through theCommandSpec
(not sure whether something like this exists in picocli), or by calling an interface method on the command to be executed before and after execution?Beta Was this translation helpful? Give feedback.
All reactions