diff --git a/cmd/updateref.go b/cmd/updateref.go index a23810d..640f34d 100644 --- a/cmd/updateref.go +++ b/cmd/updateref.go @@ -46,7 +46,6 @@ func (r report) String() string { var updateRefCmd = &cobra.Command{ Use: "update-ref [flags] -s ...", Short: "Update target refs to match source", - Args: cobra.MinimumNArgs(1), PreRunE: validateFlags, RunE: runUpdateRefCmd, } @@ -56,6 +55,8 @@ func init() { updateRefCmd.MarkFlagRequired("source") viper.BindPFlag("source", updateRefCmd.Flags().Lookup("source")) + viper.BindEnv("targets", "GHUP_TARGETS") + refTypes := []string{"heads", "tags"} defaultSourceType := choiceflag.NewChoiceFlag(refTypes) @@ -105,7 +106,16 @@ func runUpdateRefCmd(cmd *cobra.Command, args []string) (err error) { sourceObject = sourceRef.Object.GetSHA() } - targetRefNames := args + var targetRefNames []string + if len(args) > 0 { + targetRefNames = args + } else { + targetRefNames = viper.GetStringSlice("targets") + } + + if len(targetRefNames) == 0 { + return errors.New("no target refs specified") + } // ensure all target refs are properly qualified for i, targetRefName := range targetRefNames {