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

Accessing writeOut from actions #2277

Closed
hypeJunction opened this issue Nov 1, 2024 · 3 comments
Closed

Accessing writeOut from actions #2277

hypeJunction opened this issue Nov 1, 2024 · 3 comments

Comments

@hypeJunction
Copy link

I am working on a web app that doesn't have access to stdout and I was able to replace the output of the program with .configureOutput(), but I am not really sure how I would access the API from inside the actions. All examples use console, and I don't see any public API to write/print with Command. For now, I am using a proxy on top of window.console to be able to print from the actions, but perhaps there is a more elegant way, or something that I am missing.

@shadowspawn
Copy link
Collaborator

There isn't a custom API for using writeOut and writeErr directly. The main use of writeOut is displaying the help, and there are .help() and .outputHelp() routines to trigger that directly. For errors, there is the .error() method to display and handle a custom error the same way Commander does.

However, you can retrieve the configured output and use it yourself:

program
  .action((options, command) => {
    const output = command.configureOutput();
    output.writeOut('Hello, world!\n');
  });

@shadowspawn
Copy link
Collaborator

An answer was provided, and no further activity in a month. Closing this as resolved.

Feel free to open a new issue if it comes up again, with new information and renewed interest.

@hypeJunction
Copy link
Author

All good, thanks a lot. Our work is on pause for now, but we will pick it up later. I will let you know how it goes.

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

No branches or pull requests

2 participants