Skip to content
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

fix: Preserve new lines when buffering #44

Closed

Commits on Aug 16, 2023

  1. fix: Preserve new lines when buffering

    Instead of writing a `println()` which prints to stdout, write the new line character tot he `io.Writer`, this way it is preserved, otherwise, the character is lost.
    
    This way, the code of `tf-summarize` can be used as a library inside your Go code rather than a executable binary and the expected output is the same.
    
    Simple test code:
    ```
    package main
    
    import (
    	"bytes"
    	"os"
    
    	"github.com/dineshba/tf-summarize/parser"
    	"github.com/dineshba/tf-summarize/reader"
    	"github.com/dineshba/tf-summarize/writer"
    )
    
    func main() {
    	planOutputFile := "/tmp/plan"
    	newReader, err := reader.CreateReader(os.Stdin, []string{planOutputFile})
    	if err != nil {
    		panic(err)
    	}
    	input, err := newReader.Read()
    	newParser, err := parser.CreateParser(input, newReader.Name())
    	terraformState, err := newParser.Parse()
    	if err != nil {
    		panic(err)
    	}
    	terraformState.FilterNoOpResources()
    	newWriter := writer.CreateWriter(false, false, false, true, false, terraformState)
    
    	var b bytes.Buffer
    	newWriter.Write(&b)
    
    	println(b.String())
    
    }
    ```
    pmoncadaisla authored Aug 16, 2023
    Configuration menu
    Copy the full SHA
    9d5a250 View commit details
    Browse the repository at this point in the history