Return values
Is there an existing issue that is already proposing this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe it
I need some way of returning values from a command (e.g. strings). But I see commands only return void.
Describe the solution you'd like
Return values from executed command
E.g.
MY_VAL=`node dist/cli.ts my-command --some-options` # suppose it returns 'hello!'
echo $MY_VAL # return 'hello'
I see the signature of the cmd.run interface is Promise<void>
Is there any way of returning values?
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
Bash scripting, process forking
Technically, the output of process.stdout is what would get assigned to that variable. So a simple process.stdout.write('Whatever') would set $MY_VAL to 'Whatever'
Technically, the output of
process.stdoutis what would get assigned to that variable. So a simpleprocess.stdout.write('Whatever')would set$MY_VALto'Whatever'
Thanks for the workaround. Effective although it feels a bit hacky. Maybe finding a way of returning a value, e.g. via a callback or promise, would make it just more clean IMHO
If the run were allowed to return a value, the underlying service runner would do that same thing of process.stdout.write(result). It's not really hacky, it's just how return values in shell scripting works. I'll think about allowing it to return, but at the very least I could write something into the documentation about it
If the
runwere allowed to return a value, the underlying service runner would do that same thing ofprocess.stdout.write(result). It's not really hacky, it's just how return values in shell scripting works. I'll think about allowing it to return, but at the very least I could write something into the documentation about it
Yes, I think it's a good idea to update the docs. I also noticed that if you use a logger, the process.stdout.write(result) will include the logger output (except if this is redirected somewhere else).