99 "path/filepath"
1010 "strconv"
1111 "strings"
12- "text/tabwriter"
1312 "time"
1413
1514 "github.com/pepabo/xpoint-cli/internal/xpoint"
@@ -487,15 +486,13 @@ func runDocumentSearch(cmd *cobra.Command, args []string) error {
487486 }
488487
489488 return render (res , resolveOutputFormat (docSearchOutput ), docSearchJQ , func () error {
490- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
491- defer w .Flush ()
492489 fmt .Fprintf (os .Stdout , "total: %d\n " , res .TotalCount )
493- fmt .Fprintln (w , "DOCID\t FORM_NAME\t WRITER\t WRITE_DATETIME\t STEP\t STAT\t TITLE1" )
490+ w := newTable (os .Stdout ,
491+ "DOCID" , "FORM_NAME" , "WRITER" , "WRITE_DATETIME" , "STEP" , "STAT" , "TITLE1" )
494492 for _ , it := range res .Items {
495- fmt .Fprintf (w , "%d\t %s\t %s\t %s\t %d\t %d\t %s\n " ,
496- it .DocID , it .Form .Name , it .Writer , it .WriteDatetime , it .Step , it .Stat , it .Title1 ,
497- )
493+ w .AddRow (it .DocID , it .Form .Name , it .Writer , it .WriteDatetime , it .Step , it .Stat , it .Title1 )
498494 }
495+ w .Print ()
499496 return nil
500497 })
501498}
@@ -534,10 +531,9 @@ func runDocumentCreate(cmd *cobra.Command, args []string) error {
534531 }
535532
536533 return render (& view , resolveOutputFormat (docCreateOutput ), docCreateJQ , func () error {
537- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
538- defer w .Flush ()
539- fmt .Fprintln (w , "DOCID\t MESSAGE_TYPE\t MESSAGE\t URL" )
540- fmt .Fprintf (w , "%d\t %d\t %s\t %s\n " , view .DocID , view .MessageType , view .Message , view .URL )
534+ w := newTable (os .Stdout , "DOCID" , "MESSAGE_TYPE" , "MESSAGE" , "URL" )
535+ w .AddRow (view .DocID , view .MessageType , view .Message , view .URL )
536+ w .Print ()
541537 return nil
542538 })
543539}
@@ -586,10 +582,9 @@ func runDocumentEdit(cmd *cobra.Command, args []string) error {
586582 }
587583
588584 return render (res , resolveOutputFormat (docEditOutput ), docEditJQ , func () error {
589- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
590- defer w .Flush ()
591- fmt .Fprintln (w , "DOCID\t MESSAGE_TYPE\t MESSAGE" )
592- fmt .Fprintf (w , "%d\t %d\t %s\n " , res .DocID , res .MessageType , res .Message )
585+ w := newTable (os .Stdout , "DOCID" , "MESSAGE_TYPE" , "MESSAGE" )
586+ w .AddRow (res .DocID , res .MessageType , res .Message )
587+ w .Print ()
593588 return nil
594589 })
595590}
@@ -615,10 +610,9 @@ func runDocumentDelete(cmd *cobra.Command, args []string) error {
615610 }
616611
617612 return render (res , resolveOutputFormat (docDeleteOutput ), docDeleteJQ , func () error {
618- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
619- defer w .Flush ()
620- fmt .Fprintln (w , "MESSAGE_TYPE\t MESSAGE" )
621- fmt .Fprintf (w , "%d\t %s\n " , res .MessageType , res .Message )
613+ w := newTable (os .Stdout , "MESSAGE_TYPE" , "MESSAGE" )
614+ w .AddRow (res .MessageType , res .Message )
615+ w .Print ()
622616 return nil
623617 })
624618}
@@ -916,10 +910,9 @@ func runDocumentCommentAdd(cmd *cobra.Command, args []string) error {
916910 return err
917911 }
918912 return render (res , resolveOutputFormat (docCommentAddOutput ), docCommentAddJQ , func () error {
919- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
920- defer w .Flush ()
921- fmt .Fprintln (w , "DOCID\t SEQ\t MESSAGE_TYPE\t MESSAGE" )
922- fmt .Fprintf (w , "%d\t %d\t %d\t %s\n " , res .DocID , res .Seq , res .MessageType , res .Message )
913+ w := newTable (os .Stdout , "DOCID" , "SEQ" , "MESSAGE_TYPE" , "MESSAGE" )
914+ w .AddRow (res .DocID , res .Seq , res .MessageType , res .Message )
915+ w .Print ()
923916 return nil
924917 })
925918}
@@ -938,16 +931,15 @@ func runDocumentCommentGet(cmd *cobra.Command, args []string) error {
938931 return err
939932 }
940933 return render (res , resolveOutputFormat (docCommentGetOutput ), docCommentGetJQ , func () error {
941- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
942- defer w .Flush ()
943- fmt .Fprintln (w , "SEQ\t ATTENTION\t WRITER\t WRITE_DATE\t CONTENT" )
934+ w := newTable (os .Stdout , "SEQ" , "ATTENTION" , "WRITER" , "WRITE_DATE" , "CONTENT" )
944935 for _ , cm := range res .CommentList {
945936 attention := "-"
946937 if cm .AttentionFlg {
947938 attention = "*"
948939 }
949- fmt . Fprintf ( w , "%s \t %s \t %s \t %s \t %s \n " , cm .SeqNo , attention , cm .WriterName , cm .WriteDate , cm .Content )
940+ w . AddRow ( cm .SeqNo , attention , cm .WriterName , cm .WriteDate , cm .Content )
950941 }
942+ w .Print ()
951943 return nil
952944 })
953945}
@@ -990,10 +982,9 @@ func runDocumentCommentEdit(cmd *cobra.Command, args []string) error {
990982 return err
991983 }
992984 return render (res , resolveOutputFormat (docCommentEditOutput ), docCommentEditJQ , func () error {
993- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
994- defer w .Flush ()
995- fmt .Fprintln (w , "DOCID\t SEQ\t MESSAGE_TYPE\t MESSAGE" )
996- fmt .Fprintf (w , "%d\t %d\t %d\t %s\n " , res .DocID , res .Seq , res .MessageType , res .Message )
985+ w := newTable (os .Stdout , "DOCID" , "SEQ" , "MESSAGE_TYPE" , "MESSAGE" )
986+ w .AddRow (res .DocID , res .Seq , res .MessageType , res .Message )
987+ w .Print ()
997988 return nil
998989 })
999990}
@@ -1019,10 +1010,9 @@ func runDocumentCommentDelete(cmd *cobra.Command, args []string) error {
10191010 return err
10201011 }
10211012 return render (res , resolveOutputFormat (docCommentDeleteOutput ), docCommentDeleteJQ , func () error {
1022- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
1023- defer w .Flush ()
1024- fmt .Fprintln (w , "DOCID\t SEQ\t MESSAGE_TYPE\t MESSAGE" )
1025- fmt .Fprintf (w , "%d\t %d\t %d\t %s\n " , res .DocID , res .Seq , res .MessageType , res .Message )
1013+ w := newTable (os .Stdout , "DOCID" , "SEQ" , "MESSAGE_TYPE" , "MESSAGE" )
1014+ w .AddRow (res .DocID , res .Seq , res .MessageType , res .Message )
1015+ w .Print ()
10261016 return nil
10271017 })
10281018}
0 commit comments