(f *cmdutil.Factory, runF func(*UploadOptions) error)
| 30 | } |
| 31 | |
| 32 | func NewCmdUpload(f *cmdutil.Factory, runF func(*UploadOptions) error) *cobra.Command { |
| 33 | opts := &UploadOptions{ |
| 34 | IO: f.IOStreams, |
| 35 | HttpClient: f.HttpClient, |
| 36 | } |
| 37 | |
| 38 | cmd := &cobra.Command{ |
| 39 | Use: "upload <tag> <files>...", |
| 40 | Short: "Upload assets to a release", |
| 41 | Long: heredoc.Docf(` |
| 42 | Upload asset files to a GitHub Release. |
| 43 | |
| 44 | To define a display label for an asset, append text starting with %[1]s#%[1]s after the |
| 45 | file name. |
| 46 | |
| 47 | When using %[1]s--clobber%[1]s, existing assets are deleted before new assets are uploaded. |
| 48 | If the upload fails, the original assets will be lost. |
| 49 | `, "`"), |
| 50 | Args: cobra.MinimumNArgs(2), |
| 51 | RunE: func(cmd *cobra.Command, args []string) error { |
| 52 | // support `-R, --repo` override |
| 53 | opts.BaseRepo = f.BaseRepo |
| 54 | |
| 55 | opts.TagName = args[0] |
| 56 | |
| 57 | var err error |
| 58 | opts.Assets, err = shared.AssetsFromArgs(args[1:]) |
| 59 | if err != nil { |
| 60 | return err |
| 61 | } |
| 62 | |
| 63 | opts.Concurrency = 5 |
| 64 | |
| 65 | if runF != nil { |
| 66 | return runF(opts) |
| 67 | } |
| 68 | return uploadRun(opts) |
| 69 | }, |
| 70 | } |
| 71 | |
| 72 | cmd.Flags().BoolVar(&opts.OverwriteExisting, "clobber", false, "Delete and re-upload existing assets of the same name") |
| 73 | |
| 74 | return cmd |
| 75 | } |
| 76 | |
| 77 | func uploadRun(opts *UploadOptions) error { |
| 78 | httpClient, err := opts.HttpClient() |
nothing calls this directly
no test coverage detected