-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrenameFlow.go
More file actions
65 lines (56 loc) · 1.56 KB
/
renameFlow.go
File metadata and controls
65 lines (56 loc) · 1.56 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
package main
import (
"fmt"
"io"
"net/http"
"github.com/kosli-dev/cli/internal/requests"
"github.com/spf13/cobra"
)
const renameFlowShortDesc = `Rename a Kosli flow.`
const renameFlowLongDesc = renameFlowShortDesc + `
The flow will remain accessible under its old name until that name is taken by another flow.
`
const renameFlowExample = `
# rename a Kosli flow:
kosli rename flow oldName newName \
--api-token yourAPIToken \
--org yourOrgName
`
type RenameFlowPayload struct {
NewName string `json:"new_name"`
}
func newRenameFlowCmd(out io.Writer) *cobra.Command {
payload := new(RenameFlowPayload)
cmd := &cobra.Command{
Use: "flow OLD_NAME NEW_NAME",
Short: renameFlowShortDesc,
Long: renameFlowLongDesc,
Example: renameFlowExample,
Args: cobra.ExactArgs(2),
PreRunE: func(cmd *cobra.Command, args []string) error {
err := RequireGlobalFlags(global, []string{"Org", "ApiToken"})
if err != nil {
return ErrorBeforePrintingUsage(cmd, err.Error())
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
url := fmt.Sprintf("%s/api/v2/flows/%s/%s/rename", global.Host, global.Org, args[0])
payload.NewName = args[1]
reqParams := &requests.RequestParams{
Method: http.MethodPut,
URL: url,
Payload: payload,
DryRun: global.DryRun,
Password: global.ApiToken,
}
_, err := kosliClient.Do(reqParams)
if err == nil && global.DryRun == "false" {
logger.Info("flow %s was renamed to %s", args[0], payload.NewName)
}
return err
},
}
addDryRunFlag(cmd)
return cmd
}