Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return values #1122

Open
1 task done
lamuertepeluda opened this issue Apr 22, 2024 · 4 comments
Open
1 task done

Return values #1122

lamuertepeluda opened this issue Apr 22, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@lamuertepeluda
Copy link

Is there an existing issue that is already proposing this?

  • 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

@lamuertepeluda lamuertepeluda added the enhancement New feature or request label Apr 22, 2024
@jmcdo29
Copy link
Owner

jmcdo29 commented Apr 22, 2024

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'

@lamuertepeluda
Copy link
Author

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'

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

@jmcdo29
Copy link
Owner

jmcdo29 commented Apr 23, 2024

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

@lamuertepeluda
Copy link
Author

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

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants