From b47255d0621cc3324b55aef60a42bb70b3d2a3cb Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 9 Jun 2017 17:35:11 -0600 Subject: [PATCH] commands/command_migrate: wire up subcommands --- commands/command_migrate.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/commands/command_migrate.go b/commands/command_migrate.go index fa519013..9e3d4fc4 100644 --- a/commands/command_migrate.go +++ b/commands/command_migrate.go @@ -4,9 +4,33 @@ import ( "github.com/spf13/cobra" ) -func migrateCommand(cmd *cobra.Command, args []string) { -} +var ( + // migrateIncludeRefs is a set of Git references to explicitly include + // in the migration. + migrateIncludeRefs []string + // migrateExcludeRefs is a set of Git references to explicitly exclude + // in the migration. + migrateExcludeRefs []string +) func init() { - RegisterCommand("migrate", migrateCommand, nil) + RegisterCommand("migrate", nil, func(cmd *cobra.Command) { + // Adding flags directly to cmd.Flags() doesn't apply those + // flags to any subcommands of the root. Therefore, loop through + // each subcommand specifically, and include common arguments to + // each. + // + // Once done, link each orphaned command to the + // `git-lfs-migrate(1)` command as a subcommand (child). + + for _, subcommand := range []*cobra.Command{} { + subcommand.Flags().StringVarP(&includeArg, "include", "I", "", "Include a list of paths") + subcommand.Flags().StringVarP(&excludeArg, "exclude", "X", "", "Exclude a list of paths") + + subcommand.Flags().StringSliceVar(&migrateIncludeRefs, "include-ref", nil, "An explicit list of refs to include") + subcommand.Flags().StringSliceVar(&migrateExcludeRefs, "exclude-ref", nil, "An explicit list of refs to exclude") + + cmd.AddCommand(subcommand) + } + }) }