diff --git a/pkg/cmd/fixtures.go b/pkg/cmd/fixtures.go index d0d0ec90..bf8a3183 100644 --- a/pkg/cmd/fixtures.go +++ b/pkg/cmd/fixtures.go @@ -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, @@ -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 diff --git a/pkg/validators/cmds.go b/pkg/validators/cmds.go index a0f8e433..9f5e4ea9 100644 --- a/pkg/validators/cmds.go +++ b/pkg/validators/cmds.go @@ -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 + } +}