Skip to content

Commit

Permalink
fix(update-ref): set targets via environment variable (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
isometry authored Oct 7, 2024
1 parent 12ff912 commit 2d92186
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/updateref.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (r report) String() string {
var updateRefCmd = &cobra.Command{
Use: "update-ref [flags] -s <source> <target> ...",
Short: "Update target refs to match source",
Args: cobra.MinimumNArgs(1),
PreRunE: validateFlags,
RunE: runUpdateRefCmd,
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2d92186

Please sign in to comment.