diff --git a/cmd/pretty.go b/cmd/pretty.go index 88d603a..d94c9a1 100644 --- a/cmd/pretty.go +++ b/cmd/pretty.go @@ -1,7 +1,11 @@ package cmd import ( + "bufio" "fmt" + "log" + "os" + "strings" "github.com/spf13/cobra" ) @@ -14,6 +18,24 @@ var prettyCmd = &cobra.Command { Use: "pretty", Run: func(cmd *cobra.Command, args []string) { var filename = args[0] - fmt.Printf("Run the pretty command with filename %s", filename) + f, err := os.Open(filename) + if err != nil { + log.Fatal(err) + } + + defer f.Close() + + scanner := bufio.NewScanner(f) + + for scanner.Scan() { + line := scanner.Text() + formattedLine := strings.Replace(line, "\\n", "\n", -1) + formattedLine = strings.Replace(formattedLine, "\\t", "\t", -1) + fmt.Printf(formattedLine) + } + + if err := scanner.Err(); err != nil { + log.Fatal(err) + } }, }