| 41 | } |
| 42 | |
| 43 | func NewCmdDownload(f *cmdutil.Factory, runF func(*DownloadOptions) error) *cobra.Command { |
| 44 | opts := &DownloadOptions{ |
| 45 | IO: f.IOStreams, |
| 46 | HttpClient: f.HttpClient, |
| 47 | } |
| 48 | |
| 49 | cmd := &cobra.Command{ |
| 50 | Use: "download [<tag>]", |
| 51 | Short: "Download release assets", |
| 52 | Long: heredoc.Docf(` |
| 53 | Download assets from a GitHub release. |
| 54 | |
| 55 | Without an explicit tag name argument, assets are downloaded from the |
| 56 | latest release in the project. In this case, %[1]s--pattern%[1]s or %[1]s--archive%[1]s |
| 57 | is required. |
| 58 | `, "`"), |
| 59 | Example: heredoc.Doc(` |
| 60 | # Download all assets from a specific release |
| 61 | $ gh release download v1.2.3 |
| 62 | |
| 63 | # Download only Debian packages for the latest release |
| 64 | $ gh release download --pattern '*.deb' |
| 65 | |
| 66 | # Specify multiple file patterns |
| 67 | $ gh release download -p '*.deb' -p '*.rpm' |
| 68 | |
| 69 | # Download the archive of the source code for a release |
| 70 | $ gh release download v1.2.3 --archive=zip |
| 71 | `), |
| 72 | Args: cobra.MaximumNArgs(1), |
| 73 | RunE: func(cmd *cobra.Command, args []string) error { |
| 74 | // support `-R, --repo` override |
| 75 | opts.BaseRepo = f.BaseRepo |
| 76 | |
| 77 | if len(args) == 0 { |
| 78 | if len(opts.FilePatterns) == 0 && opts.ArchiveType == "" { |
| 79 | return cmdutil.FlagErrorf("`--pattern` or `--archive` is required when downloading the latest release") |
| 80 | } |
| 81 | } else { |
| 82 | opts.TagName = args[0] |
| 83 | } |
| 84 | |
| 85 | if err := cmdutil.MutuallyExclusive("specify only one of `--clobber` or `--skip-existing`", opts.OverwriteExisting, opts.SkipExisting); err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | if err := cmdutil.MutuallyExclusive("specify only one of `--dir` or `--output`", opts.Destination != ".", opts.OutputFile != ""); err != nil { |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | // check archive type option validity |
| 94 | if err := checkArchiveTypeOption(opts); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | opts.Concurrency = 5 |
| 99 | |
| 100 | if runF != nil { |