@@ -2,10 +2,12 @@ package commands
22
33import (
44 "context"
5+ "encoding/csv"
56 "fmt"
67 "os"
78 "path/filepath"
89 "sort"
10+ "strconv"
911 "time"
1012
1113 "github.com/augmentable-dev/tickgit/pkg/comments"
@@ -14,7 +16,11 @@ import (
1416 "github.com/spf13/cobra"
1517)
1618
19+ var csvOutput bool
20+
1721func init () {
22+ todosCmd .Flags ().BoolVar (& csvOutput , "csv-output" , false , "specify whether or not output should be in CSV format" )
23+
1824 rootCmd .AddCommand (todosCmd )
1925}
2026
@@ -63,6 +69,38 @@ var todosCmd = &cobra.Command{
6369
6470 s .Stop ()
6571
66- todos .WriteTodos (foundToDos , os .Stdout )
72+ if csvOutput {
73+ w := csv .NewWriter (os .Stdout )
74+ err := w .Write ([]string {
75+ "text" , "file_path" , "start_line" , "start_position" , "end_line" , "end_position" , "author" , "author_email" , "author_sha" , "author_time" ,
76+ })
77+ handleError (err , s )
78+
79+ for _ , todo := range foundToDos {
80+ err := w .Write ([]string {
81+ todo .String ,
82+ todo .FilePath ,
83+ strconv .Itoa (todo .StartLocation .Line ),
84+ strconv .Itoa (todo .StartLocation .Pos ),
85+ strconv .Itoa (todo .EndLocation .Line ),
86+ strconv .Itoa (todo .EndLocation .Pos ),
87+ todo .Blame .Author .Name ,
88+ todo .Blame .Author .Email ,
89+ todo .Blame .SHA ,
90+ todo .Blame .Author .When .Format (time .RFC3339 ),
91+ })
92+ handleError (err , s )
93+ }
94+
95+ // Write any buffered data to the underlying writer (standard output).
96+ w .Flush ()
97+
98+ err = w .Error ()
99+ handleError (err , s )
100+
101+ } else {
102+ todos .WriteTodos (foundToDos , os .Stdout )
103+ }
104+
67105 },
68106}
0 commit comments