sway/forc-tracing
zees-dev dffa29c599
feat: forc call json output (#7156)
## Description

This PR adds JSON output support for `forc-call` CLI.

Additionally, it adds JSON support for `tracing-subscriber` in
`forc-tracing` - with option to omit logs from other libraries (via
regex).
- JSON tracing-subscriber ignores colored output
- Forc-call hooks into this tracing-subscriber (using `Json` variant) to
output JSON response

### Changelog

This pull request introduces enhancements to the `forc-call` plugin,
focusing on improving output formatting, streamlining verbosity
handling, and updating test cases to reflect these changes.
The most significant updates include the addition of a JSON output
format, the removal of the `Verbosity` struct, and modifications to test
cases to handle optional results.

### Output Formatting Enhancements:
* Added a new `Json` variant to the `OutputFormat` enum for outputting
full tracing information in JSON format. Implemented the `Write` trait
for `OutputFormat` to handle different output styles.
(`forc-plugins/forc-client/src/cmd/call.rs`,
[forc-plugins/forc-client/src/cmd/call.rsR60-R87](diffhunk://#diff-466e2f9659cab303594eb73a846768ecdbc1a13030e5869cdac51ddde87dd313R60-R87))
* Updated the `Command` struct to include a short option (`-o`) for
specifying the output format.
(`forc-plugins/forc-client/src/cmd/call.rs`,
[forc-plugins/forc-client/src/cmd/call.rsL319-R319](diffhunk://#diff-466e2f9659cab303594eb73a846768ecdbc1a13030e5869cdac51ddde87dd313L319-R319))

### Verbosity Handling Simplification:
* Removed the `Verbosity` struct and its associated methods. Verbosity
is now directly represented as an integer (`cmd.verbosity`) for
simplicity. (`forc-plugins/forc-client/src/cmd/call.rs`,
[[1]](diffhunk://#diff-466e2f9659cab303594eb73a846768ecdbc1a13030e5869cdac51ddde87dd313R60-R87);
`forc-plugins/forc-client/src/op/call/call_function.rs`,
[[2]](diffhunk://#diff-7da99987eeed69f070b781a5692d3acc7028308b8538ca129d79452ccc057fdeL2-R2)
[[3]](diffhunk://#diff-7da99987eeed69f070b781a5692d3acc7028308b8538ca129d79452ccc057fdeL54-L57)
[[4]](diffhunk://#diff-7da99987eeed69f070b781a5692d3acc7028308b8538ca129d79452ccc057fdeL181-R185)
[[5]](diffhunk://#diff-7da99987eeed69f070b781a5692d3acc7028308b8538ca129d79452ccc057fdeL216-R227)

### Test Case Updates:
* Modified test cases to handle optional results by calling `.unwrap()`
on the `result` field where applicable. This ensures compatibility with
changes to how results are processed.
(`forc-plugins/forc-client/src/op/call/call_function.rs`,
[[1]](diffhunk://#diff-7da99987eeed69f070b781a5692d3acc7028308b8538ca129d79452ccc057fdeL356-R387)
through
[[2]](diffhunk://#diff-7da99987eeed69f070b781a5692d3acc7028308b8538ca129d79452ccc057fdeL661-R710)

These changes improve the usability and maintainability of the
`forc-call` plugin, making it more robust and user-friendly.

Note: This is a pre-requisite to resolve
https://github.com/FuelLabs/sway/issues/7019; the output script in the
JSON can be directly parsed into a `tx.json` file for `forc-debug`.

## Checklist

- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [ ] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

---------

Co-authored-by: z <zees-dev@users.noreply.github.com>
2025-05-09 20:07:27 +12:00
..
src feat: forc call json output (#7156) 2025-05-09 20:07:27 +12:00
Cargo.toml feat: forc call json output (#7156) 2025-05-09 20:07:27 +12:00