# Stdout behaviour of \`tuist graph\`

**URL:** <https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384>\
**Category:** Ideas\
**Created:** [February 20, 2025, 9:50am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384 "2025-02-20T09:50:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexanderwe](https://community.tuist.dev/user_avatar/community.tuist.dev/alexanderwe/32/378_2.png) [@alexanderwe](https://community.tuist.dev/u/alexanderwe)\
**Post date:** [February 20, 2025, 9:50am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/1 "2025-02-20T09:50:23Z")

</div>

While using `tuist graph --format json` I noticed that it does not play nicely with expected CLI behaviour:

1. It does automatically pipe the graph JSON content into a file. It would be great if the graph content can be piped to stdout in order to also play nicely with existing CLI tools. We could then also pipe the content into tools like `jq`
2. When running `tuist graph --format JSON` it does output additional log messages which would mess up piping the data. E.g. it logs things like warnings in the project setup.

What you think about this things ? Are they valid and worth to change ?

Looking forward to your opinions !

---

<div class="post-metadata">

**Author:** ![pepicrft](https://community.tuist.dev/user_avatar/community.tuist.dev/pepicrft/32/5_2.png) [@pepicrft](https://community.tuist.dev/u/pepicrft)\
**Post date:** [February 20, 2025, 11:32am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/2 "2025-02-20T11:32:33Z")

</div>

Hi @alexanderwe

We changed our approach to [logging](https://github.com/tuist/tuist/pull/7261) recently, and that might have caused a regression.

> 1. It does automatically pipe the graph JSON content into a file. It would be great if the graph content can be piped to stdout in order to also play nicely with existing CLI tools. We could then also pipe the content into tools like `jq`

I’m on board with this. Three ides for how we can go about it:

- Adjust the default behavior to output to stdout. One can then pipe that to a file using pipe operators. It’s a breaking change, and I’d expect some users to be using this feature already.
- Add a new option to force the output to go to standard output `--output stdout`. I personally don’t like this one because there are some formats like image for which that option doesn’t apply.
- Add a new format type, `stdout-json`, `tuist graph --format stdout-json`

> 1. When running `tuist graph --format JSON` it does output additional log messages which would mess up piping the data. E.g. it logs things like warnings in the project setup.

We shouldn’t output anything else when the format is `json`. We have some [generic logic](https://github.com/tuist/tuist/blob/a3702fc219fecb0215c854f80710647207a0950c/Sources/TuistKit/Utils/LogsController.swift#L25) that sets a logger when it detects a `--json` argument, but it doesn’t work with the above scenario. Two options here:

- We can revisit the presentation of `GraphCommand` to ensure nothing is output to the user if the format is `json`.
- Adjust [this logic](https://github.com/tuist/tuist/blob/a3702fc219fecb0215c854f80710647207a0950c/Sources/TuistKit/Utils/LogsController.swift#L25) to work if any argument contains the string `json`.

I lean on the former.

---

<div class="post-metadata">

**Author:** ![alexanderwe](https://community.tuist.dev/user_avatar/community.tuist.dev/alexanderwe/32/378_2.png) [@alexanderwe](https://community.tuist.dev/u/alexanderwe)\
**Post date:** [February 20, 2025, 12:56pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/3 "2025-02-20T12:56:28Z")

</div>

> Adjust the default behavior to output to stdout. One can then pipe that to a file using pipe operators. It’s a breaking change, and I’d expect some users to be using this feature already.

I personally would prefer to use stdout per default, even though it’s maybe a breaking change. It would emphasise the existing “industry standards” for writing CLI applications. Especially supporting piping etc. Following e.g. [Command Line Interface Guidelines](https://clig.dev/#the-basics)

> We can revisit the presentation of `GraphCommand` to ensure nothing is output to the user if the format is `json`.

Would it be possible to only show log messages when explicitly requested ? For example in the graph command I am not sure how important it is to have the logs per default. I also read that most of the logging should go to stderr ([Command Line Interface Guidelines](https://clig.dev/#the-basics)). But I am also not too familiar with the current logging mechanisms in the CLI.

---

<div class="post-metadata">

**Author:** ![marekfort](https://community.tuist.dev/user_avatar/community.tuist.dev/marekfort/32/8_2.png) [@marekfort](https://community.tuist.dev/u/marekfort)\
**Post date:** [February 20, 2025, 3:08pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/4 "2025-02-20T15:08:03Z")

</div>

We have technically speaking made a breaking change already when changing the `tuist graph --format json` output to be in the format of `XcodeGraph` instead of `ProjectAutomation`. So, I’m in favor of updating the behavior now and keeping the old behavior for the `--legacyJSON` format option.

There should be no extra output when `--json` is passed (see [here](https://github.com/tuist/tuist/blob/main/Sources/TuistKit/Utils/LogsController.swift#L25-L29), but as @pepicrft mentioned, a regression might have snuck in.

---

<div class="post-metadata">

**Author:** ![pepicrft](https://community.tuist.dev/user_avatar/community.tuist.dev/pepicrft/32/5_2.png) [@pepicrft](https://community.tuist.dev/u/pepicrft)\
**Post date:** [February 21, 2025, 9:49am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/5 "2025-02-21T09:49:23Z")

</div>

We have a plan. @alexanderwe would you like to take it on?

---

<div class="post-metadata">

**Author:** ![alexanderwe](https://community.tuist.dev/user_avatar/community.tuist.dev/alexanderwe/32/378_2.png) [@alexanderwe](https://community.tuist.dev/u/alexanderwe)\
**Post date:** [February 21, 2025, 8:18pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/6 "2025-02-21T20:18:34Z")

</div>

@pepicrft Sure ! What is the plan exactly ?

1. Introduce the `legacyJSON` option
2. Fix the bug with unwanted output

Or something else ?

---

<div class="post-metadata">

**Author:** ![pepicrft](https://community.tuist.dev/user_avatar/community.tuist.dev/pepicrft/32/5_2.png) [@pepicrft](https://community.tuist.dev/u/pepicrft)\
**Post date:** [February 23, 2025, 10:47am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/7 "2025-02-23T10:47:35Z")

</div>

Leave —legacyJSON as it is, and apply the changes and the fix to the —json flag. @marekfort introduced that one recently (breaking change) to output an XcodeGraph instead of the schema that we previously output (hence the rename of that one to —legacyJSON)

---

<div class="post-metadata">

**Author:** ![alexanderwe](https://community.tuist.dev/user_avatar/community.tuist.dev/alexanderwe/32/378_2.png) [@alexanderwe](https://community.tuist.dev/u/alexanderwe)\
**Post date:** [February 23, 2025, 5:14pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/8 "2025-02-23T17:14:17Z")

</div>

Okay, so basically just change `--format json` to output to stdout and only to file if `--output-path` is specified. Addtionally remove that the log messages appearing on stdout.

Did I understand that correctly ?

---

<div class="post-metadata">

**Author:** ![marekfort](https://community.tuist.dev/user_avatar/community.tuist.dev/marekfort/32/8_2.png) [@marekfort](https://community.tuist.dev/u/marekfort)\
**Post date:** [February 24, 2025, 8:52am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/9 "2025-02-24T08:52:32Z")

</div>

> [@alexanderwe](#):
>
> Okay, so basically just change `--format json` to output to stdout and only to file if `--output-path` is specified. Addtionally remove that the log messages appearing on stdout.

Yes, that’s correct. And preserve the current behavior when `--legacyJSON` is used. Note the non-JSON content for that option should be stripped, too.

---

<div class="post-metadata">

**Author:** ![alexanderwe](https://community.tuist.dev/user_avatar/community.tuist.dev/alexanderwe/32/378_2.png) [@alexanderwe](https://community.tuist.dev/u/alexanderwe)\
**Post date:** [February 25, 2025, 5:50pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/10 "2025-02-25T17:50:47Z")

</div>

@marekfort @pepicrft alright understood - I am going to tackle it 🙂

Is there any timeline for it?

---

<div class="post-metadata">

**Author:** ![marekfort](https://community.tuist.dev/user_avatar/community.tuist.dev/marekfort/32/8_2.png) [@marekfort](https://community.tuist.dev/u/marekfort)\
**Post date:** [February 25, 2025, 7:11pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/11 "2025-02-25T19:11:29Z")

</div>

The sooner, the better before folks start to depend on the new `tuist graph --format json`. But of course, we understand you’d be doing this in your free time, so don’t feel pressured to rush onto this. Just let us know if you don’t have time to look into this in the following weeks. Ideally, I’d love to see this shipped in the next two weeks or so.

---

<div class="post-metadata">

**Author:** ![alexanderwe](https://community.tuist.dev/user_avatar/community.tuist.dev/alexanderwe/32/378_2.png) [@alexanderwe](https://community.tuist.dev/u/alexanderwe)\
**Post date:** [February 25, 2025, 9:42pm UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/12 "2025-02-25T21:42:26Z")

</div>

As of now this should be fine. I will start taking a look at the code to get an overview. In case of code discussions, I guess we will handle this in a PR or Slack then and not here ?

---

<div class="post-metadata">

**Author:** ![marekfort](https://community.tuist.dev/user_avatar/community.tuist.dev/marekfort/32/8_2.png) [@marekfort](https://community.tuist.dev/u/marekfort)\
**Post date:** [February 26, 2025, 9:23am UTC](https://community.tuist.dev/t/stdout-behaviour-of-tuist-graph/384/13 "2025-02-26T09:23:41Z")

</div>

> [@alexanderwe](#):
>
> In case of code discussions, I guess we will handle this in a PR or Slack then and not here ?

Yup! Feel free to create a draft PR and ping us there 🙂
