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

fix: Improve custom commands formatters and add outputs #3228

Open
wants to merge 5 commits into
base: release/2.0
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review
danimtb committed May 24, 2023
commit 78bb627d0617f784fa00230d2cd6de90bda09594
9 changes: 5 additions & 4 deletions reference/extensions/custom_commands.rst
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ For example, the ``graph info`` command uses several formatters like:
field_filter = result["field_filter"]
package_filter = result["package_filter"]
...
ConanOutput().info("Conan info command output:")
cli_out_write(f"Conan info result:\n\n{graph_info_result}")
...

@conan_subcommand(formatters={"text": format_graph_info,
@@ -153,6 +153,7 @@ For example, the ``graph info`` command uses several formatters like:
"dot": format_graph_dot})
def graph_info(conan_api, parser, subparser, *args):
...
ConanOuptup().info("Conan info command output:")
return {"graph": deps_graph,
"field_filter": args.filter,
"package_filter": args.package_filter,
@@ -168,9 +169,9 @@ $ conan graph info ... --format html

There are two standard ways of outputing information as a result of a command:
- `cli_out_write(data, fg=None, bg=None, endline="\n", indentation=0)`: This will output information
to the `stdout`. Normally used to output json as the standard format.
- `ConanOutput().info(self, msg)`: This will output information to the `stderr`.
To avoid cluttering the `stdout` with messages.
to the `stdout`. Normally used to out put the final result of the command (like a JSON).
- `ConanOutput().info(self, msg)`: This will output information to the `stderr`. Normally used to
output informational messages and avoid cluttering the `stdout` but not the final result of the command.

Command function arguments
--------------------------