Add --tag to release upload for parity with release create by CloudCorpRecords · Pull Request #172 · git-pkgs/forge · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/cli/pr_checkout_test.go
40 changes: 35 additions & 5 deletions internal/cli/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,41 @@ func releaseDeleteCmd() *cobra.Command {
return cmd
}

// uploadTagAndFile resolves the release tag and file for "release upload". The tag comes from --tag with the file as
// the only argument, or from the first of two positional arguments. tagChanged must be
// cmd.Flags().Changed("tag"): an explicitly empty --tag is an error, not an unset flag, so an
// unset script variable cannot silently select positional mode.
func uploadTagAndFile(flagTag string, tagChanged bool, args []string) (tag, file string, err error) {
if tagChanged {
if flagTag == "" {
return "", "", fmt.Errorf("--tag value must not be empty")
}
if len(args) != 1 {
return "", "", fmt.Errorf("with --tag, expected one <file> argument, got %d", len(args))
}
return flagTag, args[0], nil
}
if len(args) != releaseAssetArgs {
return "", "", fmt.Errorf("expected <tag> <file> (or --tag <tag> <file>), got %d argument(s)", len(args))
}
return args[0], args[1], nil
}

func releaseUploadCmd() *cobra.Command {
return &cobra.Command{
Use: "upload <tag> <file>",
var flagTag string

cmd := &cobra.Command{
Use: "upload (<tag> <file> | --tag <tag> <file>)",
Short: "Upload an asset to a release",
Args: cobra.ExactArgs(releaseAssetArgs),
Args: func(cmd *cobra.Command, args []string) error {
_, _, err := uploadTagAndFile(flagTag, cmd.Flags().Changed("tag"), args)
return err
},
RunE: func(cmd *cobra.Command, args []string) error {
tag := args[0]
filePath := args[1]
tag, filePath, err := uploadTagAndFile(flagTag, cmd.Flags().Changed("tag"), args)
if err != nil {
return err
}

forge, owner, repoName, _, err := resolve.Repo(flagRepo, flagForgeType)
if err != nil {
Expand Down Expand Up @@ -349,6 +376,9 @@ func releaseUploadCmd() *cobra.Command {
return nil
},
}

cmd.Flags().StringVar(&flagTag, "tag", "", "Tag name of the release (alternative to the positional <tag>)")
return cmd
}

func releaseDownloadCmd() *cobra.Command {
Expand Down
152 changes: 152 additions & 0 deletions internal/cli/release_test.go