-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathcomplete.go
More file actions
67 lines (57 loc) · 1.98 KB
/
Copy pathcomplete.go
File metadata and controls
67 lines (57 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package workflow
import (
"fmt"
"strconv"
"github.com/planetscale/cli/internal/cmdutil"
"github.com/planetscale/cli/internal/printer"
ps "github.com/planetscale/planetscale-go/planetscale"
"github.com/spf13/cobra"
)
func CompleteCmd(ch *cmdutil.Helper) *cobra.Command {
cmd := &cobra.Command{
Use: "complete <database> <number>",
Short: "Mark a workflow as complete",
Long: `Mark a workflow as complete. This is done after the cutover is confirmed and the application is working as expected.`,
Args: cmdutil.RequiredArgs("database", "number"),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
db, num := args[0], args[1]
wfCtx := errorContext{Org: ch.Config.Organization, Database: db, Number: num}
client, err := ch.Client()
if err != nil {
return wfCtx.handle(ch, err)
}
var number uint64
number, err = strconv.ParseUint(num, 10, 64)
if err != nil {
return wfCtx.handle(ch, err)
}
end := ch.Printer.PrintProgress(fmt.Sprintf("Marking workflow %s in database %s as complete…", printer.BoldBlue(printer.Number(number)), printer.BoldBlue(db)))
defer end()
workflow, err := client.Workflows.Complete(ctx, &ps.CompleteWorkflowRequest{
Organization: ch.Config.Organization,
Database: db,
WorkflowNumber: number,
})
if err != nil {
switch cmdutil.ErrCode(err) {
case ps.ErrNotFound:
return wfCtx.handle(ch, fmt.Errorf("database %s or workflow %s does not exist in organization %s",
printer.BoldBlue(db), printer.BoldBlue(number), printer.BoldBlue(ch.Config.Organization)))
default:
return wfCtx.handle(ch, cmdutil.HandleError(err))
}
}
end()
if ch.Printer.Format() == printer.Human {
ch.Printer.Printf("Workflow %s in database %s has been marked as complete.\n",
printer.BoldBlue(printer.Number(workflow.Number)),
printer.BoldBlue(db),
)
return nil
}
return ch.Printer.PrintResource(toWorkflow(workflow))
},
}
return cmd
}