You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the scenario and circumstances that should be addressed / Describe alternatives you've considered
Tooling built around bpt frequently needs to get information from bpt. Parsing the "normal", user-friendly output for that information kind of works but is error-prone and can easily break with every update of bpt. Especially accurately detecting error reasons is... not pretty.
Describe the solution you'd like
An alternative, machine-friendly output format - like JSON - would allow reliable parsing of bpt's output.
I imagine some global option to switch to JSON output:
--output-format=json: Probably confusing because bpt --output-format=json build --output=foo looks like --output-format= refers to --output=.
--output-json: Same issue as --output-format=json.
--log-style=json: Somewhat consistent with --log-level=.
--json
All flag-style options (--output-json, --json) suffer from the fact that if additional output formats are introduced in the future more (mutually exclusive) options have to be added.
Once that flag is turned on, one of these behaviors would be expected:
All non-JSON output is suppressed. Relevant information is JSON-formatted and sent to stdout. Error messages might still appear on stderr.
All non-JSON output (including error messages) is sent to stderr. Relevant information is JSON-formatted and sent to stdout.
All non-JSON output is wrapped in a JSON object (like [info] foo bar becoming {"type": "msg", "data": {"level": "info", "msg": "foo bar"}}) and sent to stdout. Relevant information is JSON-formatted and sent to stdout as well.
Additional considerations:
It would be super helpful if errors like "repo doesn't exist", "package doesn't exist", "package already exists", etc. would get some kind of stable identifier (see Example 2).
There are various ways for separating JSON objects in the output. I'll reuse the aliases used by journalctl:
json: Output one JSON object per line, separated by newlines.
json-pretty: Like json but JSON objects are pretty-printed to make them easier to read for humans. This is not really relevant for the goal of machine-friendly output but is a developer-friendly addition that is trivially to implement if json works already.
json-seq: Output JSON objects prefixed by ASCII RS (0x1e) and suffixed by LF (0x0a). This is standardized by RFC 7464. This format even allows interleaving JSON objects and normal output lines.
Example 1
bpt repo import "$PATH_TO_REPO".
Normal output:
[info ] [nbt-local]: Imported my-app@0.1.0~1 from [.]
This is something that I have wanted to address from early on. I would very much like to provide a json-based subcommand API consisting of invoking functionality in a programmatic manner and returning data via stdout. This would be very helpful for tooling integration (e.g. editor extensions).
I'll use this ticket to track the feature. This is beyond the scope of the beta improvements, but I'll hope to get to it sooner than later.
Describe the scenario and circumstances that should be addressed / Describe alternatives you've considered
Tooling built around bpt frequently needs to get information from bpt. Parsing the "normal", user-friendly output for that information kind of works but is error-prone and can easily break with every update of bpt. Especially accurately detecting error reasons is... not pretty.
Describe the solution you'd like
An alternative, machine-friendly output format - like JSON - would allow reliable parsing of bpt's output.
I imagine some global option to switch to JSON output:
--output-format=json
: Probably confusing becausebpt --output-format=json build --output=foo
looks like--output-format=
refers to--output=
.--output-json
: Same issue as--output-format=json
.--log-style=json
: Somewhat consistent with--log-level=
.--json
All flag-style options (
--output-json
,--json
) suffer from the fact that if additional output formats are introduced in the future more (mutually exclusive) options have to be added.Once that flag is turned on, one of these behaviors would be expected:
[info] foo bar
becoming{"type": "msg", "data": {"level": "info", "msg": "foo bar"}}
) and sent to stdout. Relevant information is JSON-formatted and sent to stdout as well.Additional considerations:
journalctl
:json
: Output one JSON object per line, separated by newlines.json-pretty
: Likejson
but JSON objects are pretty-printed to make them easier to read for humans. This is not really relevant for the goal of machine-friendly output but is a developer-friendly addition that is trivially to implement ifjson
works already.json-seq
: Output JSON objects prefixed by ASCII RS (0x1e
) and suffixed by LF (0x0a
). This is standardized by RFC 7464. This format even allows interleaving JSON objects and normal output lines.Example 1
Normal output:
JSON output:
Example 2
Normal output:
JSON output:
Example 3
bpt repo ls "$PATH_TO_REPO"
Normal output:
JSON output:
The text was updated successfully, but these errors were encountered: