releases create: add --asset argument

allows to specify a file path to be attached to the release.
can be specified multiple times
This commit is contained in:
Norwin Roosen 2018-12-04 23:07:59 +01:00
parent aee6267c9c
commit f268911eca
2 changed files with 24 additions and 1 deletions

View file

@ -158,7 +158,7 @@ func initCommand(ctx *cli.Context) (*Login, string, string) {
return login, owner, repo
}
func getGlobalFlag(ctx *cli.Context, flag string) (string) {
func getGlobalFlag(ctx *cli.Context, flag string) string {
var val = ctx.String(flag)
if val == "" {
return ctx.GlobalString(flag)

View file

@ -7,6 +7,8 @@ package cmd
import (
"fmt"
"log"
"path/filepath"
"os"
"code.gitea.io/sdk/gitea"
@ -87,6 +89,10 @@ var CmdReleaseCreate = cli.Command{
Name: "prerelease, p",
Usage: "the release is a prerelease",
},
cli.StringSliceFlag{
Name: "asset, a",
Usage: "a list of files to attach to the release",
},
},
}
@ -106,5 +112,22 @@ func runReleaseCreate(ctx *cli.Context) error {
log.Fatal(err)
}
for _, asset := range ctx.StringSlice("asset") {
var file *os.File
file, err = os.Open(asset)
if err != nil {
log.Fatal(err)
}
filePath := filepath.Base(asset)
_, err = login.Client().CreateReleaseAttachment(owner, repo, release.ID, file, filePath)
if err != nil {
log.Fatal(err)
}
}
return nil
}