2222 approvalListShowHiddenDoc bool
2323 approvalListOutput string
2424 approvalListJQ string
25+
26+ approvalWaitFGID int
27+ approvalWaitFID int
28+ approvalWaitStep int
29+ approvalWaitOutput string
30+ approvalWaitJQ string
31+
32+ approvalHiddenShow bool
33+ approvalHiddenProxyUser string
34+ approvalHiddenOutput string
35+ approvalHiddenJQ string
2536)
2637
2738var approvalCmd = & cobra.Command {
@@ -36,6 +47,24 @@ var approvalListCmd = &cobra.Command{
3647 RunE : runApprovalList ,
3748}
3849
50+ var approvalWaitCmd = & cobra.Command {
51+ Use : "wait" ,
52+ Short : "Get approval counts and latest pending documents" ,
53+ Long : "Fetch approval counts and the latest pending documents via GET /api/v1/approvals/wait." ,
54+ RunE : runApprovalWait ,
55+ }
56+
57+ var approvalHiddenCmd = & cobra.Command {
58+ Use : "hidden <docid> [<docid>...]" ,
59+ Short : "Hide or show completed approval documents" ,
60+ Long : `Set the hidden flag on completed approval documents via PUT /api/v1/approvals/hidden.
61+
62+ By default the given document IDs are hidden. Pass --show to restore them.
63+ Only documents in the "承認完了" (completed) status may be specified.` ,
64+ Args : cobra .MinimumNArgs (1 ),
65+ RunE : runApprovalHidden ,
66+ }
67+
3968func init () {
4069 rootCmd .AddCommand (approvalCmd )
4170 approvalCmd .AddCommand (approvalListCmd )
@@ -51,6 +80,21 @@ func init() {
5180 f .BoolVar (& approvalListShowHiddenDoc , "show-hidden-doc" , false , "include hidden completed documents" )
5281 f .StringVarP (& approvalListOutput , "output" , "o" , "" , "output format: table|json (default: table on TTY, json otherwise)" )
5382 f .StringVar (& approvalListJQ , "jq" , "" , "apply a gojq filter to the JSON response (forces JSON output)" )
83+
84+ approvalCmd .AddCommand (approvalWaitCmd )
85+ fw := approvalWaitCmd .Flags ()
86+ fw .IntVar (& approvalWaitFGID , "fgid" , 0 , "form group ID (0 = omit)" )
87+ fw .IntVar (& approvalWaitFID , "fid" , 0 , "form ID (0 = omit)" )
88+ fw .IntVar (& approvalWaitStep , "step" , 0 , "approval step (0 = omit)" )
89+ fw .StringVarP (& approvalWaitOutput , "output" , "o" , "" , "output format: table|json (default: table on TTY, json otherwise)" )
90+ fw .StringVar (& approvalWaitJQ , "jq" , "" , "apply a gojq filter to the JSON response (forces JSON output)" )
91+
92+ approvalCmd .AddCommand (approvalHiddenCmd )
93+ fh := approvalHiddenCmd .Flags ()
94+ fh .BoolVar (& approvalHiddenShow , "show" , false , "show (un-hide) the given documents instead of hiding them" )
95+ fh .StringVar (& approvalHiddenProxyUser , "proxy-user" , "" , "proxy approver user code (required when toggling proxy-approved documents)" )
96+ fh .StringVarP (& approvalHiddenOutput , "output" , "o" , "" , "output format: table|json (default: table on TTY, json otherwise)" )
97+ fh .StringVar (& approvalHiddenJQ , "jq" , "" , "apply a gojq filter to the JSON response (forces JSON output)" )
5498}
5599
56100func runApprovalList (cmd * cobra.Command , args []string ) error {
@@ -108,3 +152,88 @@ func runApprovalList(cmd *cobra.Command, args []string) error {
108152 return nil
109153 })
110154}
155+
156+ func runApprovalWait (cmd * cobra.Command , args []string ) error {
157+ client , err := newClientFromFlags (cmd .Context ())
158+ if err != nil {
159+ return err
160+ }
161+
162+ var params xpoint.ApprovalsWaitParams
163+ if approvalWaitFGID != 0 {
164+ v := approvalWaitFGID
165+ params .FormGroupID = & v
166+ }
167+ if approvalWaitFID != 0 {
168+ v := approvalWaitFID
169+ params .FormID = & v
170+ }
171+ if approvalWaitStep != 0 {
172+ v := approvalWaitStep
173+ params .Step = & v
174+ }
175+
176+ res , err := client .GetApprovalsWait (cmd .Context (), params )
177+ if err != nil {
178+ return err
179+ }
180+
181+ return render (res , resolveOutputFormat (approvalWaitOutput ), approvalWaitJQ , func () error {
182+ w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
183+ fmt .Fprintln (w , "TYPE\t NAME\t COUNT" )
184+ for _ , s := range res .StatusList {
185+ fmt .Fprintf (w , "%d\t %s\t %d\n " , s .Type , s .Name , s .Count )
186+ }
187+ w .Flush ()
188+
189+ if len (res .WaitList ) > 0 {
190+ fmt .Fprintln (os .Stdout )
191+ fmt .Fprintln (os .Stdout , "最新の承認待ち書類:" )
192+ w2 := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
193+ fmt .Fprintln (w2 , "DOCID\t FORM_NAME\t WRITER\t WRITE_DATE\t TITLE" )
194+ for _ , d := range res .WaitList {
195+ fmt .Fprintf (w2 , "%d\t %s\t %s\t %s\t %s\n " , d .DocID , d .Name , d .WriterName , d .WriteDate , d .Title )
196+ }
197+ w2 .Flush ()
198+ }
199+ return nil
200+ })
201+ }
202+
203+ func runApprovalHidden (cmd * cobra.Command , args []string ) error {
204+ client , err := newClientFromFlags (cmd .Context ())
205+ if err != nil {
206+ return err
207+ }
208+
209+ docIDs := make ([]int , 0 , len (args ))
210+ for _ , a := range args {
211+ id , err := parseDocID (a )
212+ if err != nil {
213+ return fmt .Errorf ("invalid docid %q: %w" , a , err )
214+ }
215+ docIDs = append (docIDs , id )
216+ }
217+
218+ req := xpoint.SetApprovalsHiddenRequest {
219+ Hidden : ! approvalHiddenShow ,
220+ DocID : docIDs ,
221+ ProxyUser : approvalHiddenProxyUser ,
222+ }
223+
224+ res , err := client .SetApprovalsHidden (cmd .Context (), req )
225+ if err != nil {
226+ return err
227+ }
228+
229+ return render (res , resolveOutputFormat (approvalHiddenOutput ), approvalHiddenJQ , func () error {
230+ fmt .Fprintf (os .Stdout , "message: %s\n " , res .Message )
231+ w := tabwriter .NewWriter (os .Stdout , 0 , 0 , 2 , ' ' , 0 )
232+ defer w .Flush ()
233+ fmt .Fprintln (w , "DOCID" )
234+ for _ , id := range res .DocID {
235+ fmt .Fprintf (w , "%d\n " , id )
236+ }
237+ return nil
238+ })
239+ }
0 commit comments