-
Notifications
You must be signed in to change notification settings - Fork 4
/
clone.go
46 lines (32 loc) · 990 Bytes
/
clone.go
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
package action
import (
"bunnyshell.com/cli/pkg/api/environment"
"bunnyshell.com/cli/pkg/config"
"bunnyshell.com/cli/pkg/lib"
"github.com/spf13/cobra"
)
func init() {
options := config.GetOptions()
settings := config.GetSettings()
cloneOptions := environment.NewCloneOptions("")
command := &cobra.Command{
Use: "clone",
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
cloneOptions.ID = settings.Profile.Context.Environment
model, err := environment.Clone(cloneOptions)
if err != nil {
return lib.FormatCommandError(cmd, err)
}
cmd.Printf("\nEnvironment %s successfully cloned:\n\n", cloneOptions.ID)
return lib.FormatCommandData(cmd, model)
},
}
flags := command.Flags()
idFlag := options.Environment.GetFlag("id")
flags.AddFlag(idFlag)
_ = command.MarkFlagRequired(idFlag.Name)
cloneOptions.UpdateFlagSet(flags)
_ = command.MarkFlagRequired("name")
mainCmd.AddCommand(command)
}