99 "path/filepath"
1010 "strconv"
1111 "strings"
12- "text/tabwriter"
1312 "time"
1413
1514 "github.com/pepabo/xpoint-cli/internal/xpoint"
@@ -376,15 +375,13 @@ func runDocumentSearch(cmd *cobra.Command, args []string) error {
376375 }
377376
378377 return render (res , resolveOutputFormat (docSearchOutput ), docSearchJQ , func () error {
379- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
380- defer w .Flush ()
381378 fmt .Fprintf (os .Stdout , "total: %d\n " , res .TotalCount )
382- fmt .Fprintln (w , "DOCID\t FORM_NAME\t WRITER\t WRITE_DATETIME\t STEP\t STAT\t TITLE1" )
379+ w := newTable (os .Stdout ,
380+ "DOCID" , "FORM_NAME" , "WRITER" , "WRITE_DATETIME" , "STEP" , "STAT" , "TITLE1" )
383381 for _ , it := range res .Items {
384- fmt .Fprintf (w , "%d\t %s\t %s\t %s\t %d\t %d\t %s\n " ,
385- it .DocID , it .Form .Name , it .Writer , it .WriteDatetime , it .Step , it .Stat , it .Title1 ,
386- )
382+ w .AddRow (it .DocID , it .Form .Name , it .Writer , it .WriteDatetime , it .Step , it .Stat , it .Title1 )
387383 }
384+ w .Print ()
388385 return nil
389386 })
390387}
@@ -423,10 +420,9 @@ func runDocumentCreate(cmd *cobra.Command, args []string) error {
423420 }
424421
425422 return render (& view , resolveOutputFormat (docCreateOutput ), docCreateJQ , func () error {
426- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
427- defer w .Flush ()
428- fmt .Fprintln (w , "DOCID\t MESSAGE_TYPE\t MESSAGE\t URL" )
429- fmt .Fprintf (w , "%d\t %d\t %s\t %s\n " , view .DocID , view .MessageType , view .Message , view .URL )
423+ w := newTable (os .Stdout , "DOCID" , "MESSAGE_TYPE" , "MESSAGE" , "URL" )
424+ w .AddRow (view .DocID , view .MessageType , view .Message , view .URL )
425+ w .Print ()
430426 return nil
431427 })
432428}
@@ -475,10 +471,9 @@ func runDocumentEdit(cmd *cobra.Command, args []string) error {
475471 }
476472
477473 return render (res , resolveOutputFormat (docEditOutput ), docEditJQ , func () error {
478- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
479- defer w .Flush ()
480- fmt .Fprintln (w , "DOCID\t MESSAGE_TYPE\t MESSAGE" )
481- fmt .Fprintf (w , "%d\t %d\t %s\n " , res .DocID , res .MessageType , res .Message )
474+ w := newTable (os .Stdout , "DOCID" , "MESSAGE_TYPE" , "MESSAGE" )
475+ w .AddRow (res .DocID , res .MessageType , res .Message )
476+ w .Print ()
482477 return nil
483478 })
484479}
@@ -504,10 +499,9 @@ func runDocumentDelete(cmd *cobra.Command, args []string) error {
504499 }
505500
506501 return render (res , resolveOutputFormat (docDeleteOutput ), docDeleteJQ , func () error {
507- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
508- defer w .Flush ()
509- fmt .Fprintln (w , "MESSAGE_TYPE\t MESSAGE" )
510- fmt .Fprintf (w , "%d\t %s\n " , res .MessageType , res .Message )
502+ w := newTable (os .Stdout , "MESSAGE_TYPE" , "MESSAGE" )
503+ w .AddRow (res .MessageType , res .Message )
504+ w .Print ()
511505 return nil
512506 })
513507}
@@ -603,10 +597,9 @@ func runDocumentCommentAdd(cmd *cobra.Command, args []string) error {
603597 return err
604598 }
605599 return render (res , resolveOutputFormat (docCommentAddOutput ), docCommentAddJQ , func () error {
606- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
607- defer w .Flush ()
608- fmt .Fprintln (w , "DOCID\t SEQ\t MESSAGE_TYPE\t MESSAGE" )
609- fmt .Fprintf (w , "%d\t %d\t %d\t %s\n " , res .DocID , res .Seq , res .MessageType , res .Message )
600+ w := newTable (os .Stdout , "DOCID" , "SEQ" , "MESSAGE_TYPE" , "MESSAGE" )
601+ w .AddRow (res .DocID , res .Seq , res .MessageType , res .Message )
602+ w .Print ()
610603 return nil
611604 })
612605}
@@ -625,16 +618,15 @@ func runDocumentCommentGet(cmd *cobra.Command, args []string) error {
625618 return err
626619 }
627620 return render (res , resolveOutputFormat (docCommentGetOutput ), docCommentGetJQ , func () error {
628- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
629- defer w .Flush ()
630- fmt .Fprintln (w , "SEQ\t ATTENTION\t WRITER\t WRITE_DATE\t CONTENT" )
621+ w := newTable (os .Stdout , "SEQ" , "ATTENTION" , "WRITER" , "WRITE_DATE" , "CONTENT" )
631622 for _ , cm := range res .CommentList {
632623 attention := "-"
633624 if cm .AttentionFlg {
634625 attention = "*"
635626 }
636- fmt . Fprintf ( w , "%s \t %s \t %s \t %s \t %s \n " , cm .SeqNo , attention , cm .WriterName , cm .WriteDate , cm .Content )
627+ w . AddRow ( cm .SeqNo , attention , cm .WriterName , cm .WriteDate , cm .Content )
637628 }
629+ w .Print ()
638630 return nil
639631 })
640632}
@@ -677,10 +669,9 @@ func runDocumentCommentEdit(cmd *cobra.Command, args []string) error {
677669 return err
678670 }
679671 return render (res , resolveOutputFormat (docCommentEditOutput ), docCommentEditJQ , func () error {
680- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
681- defer w .Flush ()
682- fmt .Fprintln (w , "DOCID\t SEQ\t MESSAGE_TYPE\t MESSAGE" )
683- fmt .Fprintf (w , "%d\t %d\t %d\t %s\n " , res .DocID , res .Seq , res .MessageType , res .Message )
672+ w := newTable (os .Stdout , "DOCID" , "SEQ" , "MESSAGE_TYPE" , "MESSAGE" )
673+ w .AddRow (res .DocID , res .Seq , res .MessageType , res .Message )
674+ w .Print ()
684675 return nil
685676 })
686677}
@@ -706,10 +697,9 @@ func runDocumentCommentDelete(cmd *cobra.Command, args []string) error {
706697 return err
707698 }
708699 return render (res , resolveOutputFormat (docCommentDeleteOutput ), docCommentDeleteJQ , func () error {
709- w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
710- defer w .Flush ()
711- fmt .Fprintln (w , "DOCID\t SEQ\t MESSAGE_TYPE\t MESSAGE" )
712- fmt .Fprintf (w , "%d\t %d\t %d\t %s\n " , res .DocID , res .Seq , res .MessageType , res .Message )
700+ w := newTable (os .Stdout , "DOCID" , "SEQ" , "MESSAGE_TYPE" , "MESSAGE" )
701+ w .AddRow (res .DocID , res .Seq , res .MessageType , res .Message )
702+ w .Print ()
713703 return nil
714704 })
715705}
0 commit comments