-
Notifications
You must be signed in to change notification settings - Fork 361
/
fixtures.go
98 lines (81 loc) · 2.66 KB
/
fixtures.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package cmd
import (
"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/stripe/stripe-cli/pkg/config"
"github.com/stripe/stripe-cli/pkg/fixtures"
"github.com/stripe/stripe-cli/pkg/stripe"
"github.com/stripe/stripe-cli/pkg/validators"
"github.com/stripe/stripe-cli/pkg/version"
)
// FixturesCmd prints a list of all the available sample projects that users can
// generate
type FixturesCmd struct {
Cmd *cobra.Command
Cfg *config.Config
stripeAccount string
apiVersion string
apiBaseURL string
skip []string
override []string
add []string
remove []string
edit bool
}
func newFixturesCmd(cfg *config.Config) *FixturesCmd {
fixturesCmd := &FixturesCmd{
Cfg: cfg,
}
fixturesCmd.Cmd = &cobra.Command{
Use: "fixtures",
Args: validators.ExactArgs(1),
Short: "Run fixtures to populate your account with data",
Long: `Run fixtures to populate your account with data`,
RunE: fixturesCmd.runFixturesCmd,
}
fixturesCmd.Cmd.Flags().StringVar(&fixturesCmd.stripeAccount, "stripe-account", "", "Set a header identifying the connected account")
fixturesCmd.Cmd.Flags().StringArrayVar(&fixturesCmd.skip, "skip", []string{}, "Skip specific steps in the fixture")
fixturesCmd.Cmd.Flags().StringArrayVar(&fixturesCmd.override, "override", []string{}, "Override parameters in the fixture")
fixturesCmd.Cmd.Flags().StringArrayVar(&fixturesCmd.add, "add", []string{}, "Add parameters in the fixture")
fixturesCmd.Cmd.Flags().StringArrayVar(&fixturesCmd.remove, "remove", []string{}, "Remove parameters from the fixture")
fixturesCmd.Cmd.Flags().StringVar(&fixturesCmd.apiVersion, "api-version", "", "Specify API version in the fixture")
fixturesCmd.Cmd.Flags().BoolVar(&fixturesCmd.edit, "edit", false, "Edit the fixture directly in your default IDE")
// Hidden configuration flags, useful for dev/debugging
fixturesCmd.Cmd.Flags().StringVar(&fixturesCmd.apiBaseURL, "api-base", stripe.DefaultAPIBaseURL, "Sets the API base URL")
fixturesCmd.Cmd.Flags().MarkHidden("api-base") // #nosec G104
return fixturesCmd
}
func (fc *FixturesCmd) runFixturesCmd(cmd *cobra.Command, args []string) error {
version.CheckLatestVersion()
apiKey, err := fc.Cfg.Profile.GetAPIKey(false)
if err != nil {
return err
}
if len(args) == 0 {
return nil
}
fixture, err := fixtures.NewFixtureFromFile(
afero.NewOsFs(),
apiKey,
fc.stripeAccount,
fc.apiBaseURL,
args[0],
fc.skip,
fc.override,
fc.add,
fc.remove,
fc.edit,
)
if err != nil {
return err
}
_, err = fixture.Execute(cmd.Context(), fc.apiVersion)
if err != nil {
return err
}
err = fixture.UpdateEnv()
if err != nil {
return err
}
return nil
}