package main import ( "errors" "strconv" _ "code.osinet.fr/fgm/kurz/migrations" "github.com/spf13/cobra" ) var cmdMigrate = &cobra.Command{ Args: cobra.NoArgs, Long: "Custom Kurz version of Goose CLI", Short: "Top-level command for migrations. Kurz version of 'goose', without the 'create' subcommand.", Use: "migrate", } // Used by the down-to and up-to commands. var migrateTargetVersion int64 = 0 func init() { cmd.AddCommand(cmdMigrate) } func migrateVersionValidator(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New(cmd.Name() + " only accepts a single numeric version parameter") } // Arguments count was validated by cmdMigrate.Args: ExactArgs(1). target, err := strconv.ParseInt(args[0], 10, 64) if err != nil { return errors.New(cmd.Name() + " could not parse target version number") } if target < 0 { return errors.New(cmd.Name() + " version numbers must be positive") } migrateTargetVersion = target return nil }