-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
How to pipe output of cdk diff to file (without colors)? #1638
Comments
We should update the CLI to detect if a terminal is attached, like I've also hacked around it by piping to perl: |
I tried this today with version 0.36 of the CDK. When redirecting to a file some, but not all, the color codes are removed. |
Reopened due to incomplete issue resolution. |
Hi, I can't pipe the result of |
putting the answer here because this thread still comes up in many searches:
|
|
Can we get a |
I found
cdk diff
and@aws-cdk/cloudformation-diff.formatDifferences
as fabulous tools when rewriting some CFN stacks to CDK. It is really great!Yesterday I attempted to check differences between two templates with
cdk diff
but there was too many lines that has changed and it was not really tiresome to use terminal to check all of this changes, so I decided to pipe output to some text filecdk diff > out.txt
. I got an empty file, so I tried again with stderr -cdk diff 2> out.txt
and I noticed there are also saved some extra sequences for text and background colors, extract:I am not a person who gives up so easily to troubleshoot that problem, so I wrote simple JS script which utilizes the
@aws-cdk/cloudformation-diff
package to check it is related toformatDifferences
function or not. Answer is "yes, it is".Of course, I went through I wrote some quick post-processing script to ignore those sequences but personally, I would be more satisfied if this function will allow to specify if I want or not an output in a plain-text or not.
Generally speaking, it is a good practice to check if output is piped or not, and then (unless forced with some flag, like
--color
/--no-color
) do not add those colouring sequences, otherwise use them.The text was updated successfully, but these errors were encountered: