-
Notifications
You must be signed in to change notification settings - Fork 88
/
new-fixture.go
52 lines (44 loc) · 1.2 KB
/
new-fixture.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
47
48
49
50
51
52
package cli
import (
"github.com/pkg/errors"
"github.com/replicatedhq/kots/integration/replicated"
"github.com/replicatedhq/kots/integration/upload"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func NewFixture() *cobra.Command {
cmd := &cobra.Command{
Use: "new-fixture [path]",
Short: "",
Long: ``,
SilenceUsage: true,
SilenceErrors: false,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()
if len(args) == 0 {
return errors.New("need to specify the path to the app bundle")
}
if v.GetString("type") == "replicated" {
if err := replicated.GenerateTest(v.GetString("name"), args[0]); err != nil {
return err
}
return nil
}
if v.GetString("type") == "upload" {
if err := upload.GenerateTest(v.GetString("name"), args[0]); err != nil {
return err
}
return nil
}
return errors.New("not implemented")
},
}
cmd.Flags().String("type", "", "the app type to fixture")
cmd.Flags().String("name", "", "the name of the test")
cmd.MarkFlagRequired("type")
cmd.MarkFlagRequired("name")
return cmd
}