-
Notifications
You must be signed in to change notification settings - Fork 375
Closed
Description
Describe the bug
Following the example posted here: https://docs.conan.io/2/reference/extensions/custom_commands.html#decorators
Implementation of def output_json
seems to be missing call to cli_out_write
(does a return instead).
Suggested fix:
import json
from conan.api.conan_api import ConanAPI
from conan.api.output import ConanOutput, cli_out_write
from conan.cli.command import conan_command
def output_json(msg):
myjson = json.dumps({"greet": msg})
cli_out_write(myjson)
@conan_command(group="Custom commands", formatters={"json": output_json})
def hello(conan_api: ConanAPI, parser, *args):
"""
Simple command to print "Hello World!" line
"""
msg = "Hello World!"
ConanOutput().info(msg)
return msg
How to reproduce it
Implement a custom command from example extensions/commands/greet/cmd_hello.py
with following contents:
import json
from conan.api.conan_api import ConanAPI
from conan.api.output import ConanOutput
from conan.cli.command import conan_command
def output_json(msg):
return json.dumps({"greet": msg})
@conan_command(group="Custom commands", formatters={"json": output_json})
def hello(conan_api: ConanAPI, parser, *args):
"""
Simple command to print "Hello World!" line
"""
msg = "Hello World!"
ConanOutput().info(msg)
return msg
Then run conan greet:hello --format json
. There is no JSON output.
Metadata
Metadata
Assignees
Labels
No labels