Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions pkg/cmd/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newFixturesCmd(cfg *config.Config) *FixturesCmd {

fixturesCmd.Cmd = &cobra.Command{
Use: "fixtures",
Args: validators.ExactArgs(1),
Args: validators.MinimumNArgs(1),
Short: "Run fixtures to populate your account with data",
Long: `Run fixtures to populate your account with data`,
RunE: fixturesCmd.runFixturesCmd,
Expand Down Expand Up @@ -71,31 +71,34 @@ func (fc *FixturesCmd) runFixturesCmd(cmd *cobra.Command, args []string) error {
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
// Process each fixture file
for _, file := range args {
fixture, err := fixtures.NewFixtureFromFile(
afero.NewOsFs(),
apiKey,
fc.stripeAccount,
fc.apiBaseURL,
file,
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
Expand Down
25 changes: 25 additions & 0 deletions pkg/validators/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ func MaximumNArgs(num int) cobra.PositionalArgs {
return nil
}
}

// MinimumNArgs is a validator for commands to print an error when the provided
// args are less than the minimum amount
func MinimumNArgs(num int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
commandPath := getCommandPath(cmd)
argument := "positional argument"
if num > 1 {
argument = "positional arguments"
}

errorMessage := fmt.Sprintf(
"`%s` requires at least %d %s. See `%s --help` for supported flags and usage",
commandPath,
num,
argument,
commandPath,
)

if len(args) < num {
return errors.New(errorMessage)
}
return nil
}
}