@@ -32,7 +32,7 @@ import (
3232
3333// rootCmd represents the base command when called without any subcommands
3434var rootCmd = & cobra.Command {
35- Use : "gh2gcs --org kubernetes --repo release --bucket <bucket> --release-dir <release-dir> [--tags v0.0.0] [--include-prereleases] [--output-dir <temp-dir>]" ,
35+ Use : "gh2gcs --org kubernetes --repo release --bucket <bucket> --release-dir <release-dir> [--tags v0.0.0] [--include-prereleases] [--output-dir <temp-dir>] [--download-only] " ,
3636 Short : "gh2gcs uploads GitHub releases to Google Cloud Storage" ,
3737 Example : "gh2gcs --org kubernetes --repo release --bucket k8s-staging-release-test --release-dir release --tags v0.0.0,v0.0.1" ,
3838 SilenceUsage : true ,
@@ -44,14 +44,15 @@ var rootCmd = &cobra.Command{
4444}
4545
4646type options struct {
47+ downloadOnly bool
48+ includePrereleases bool
4749 org string
4850 repo string
49- tags []string
50- includePrereleases bool
5151 bucket string
5252 releaseDir string
5353 outputDir string
5454 logLevel string
55+ tags []string
5556}
5657
5758var opts = & options {}
6465 bucketFlag = "bucket"
6566 releaseDirFlag = "release-dir"
6667 outputDirFlag = "output-dir"
68+ downloadOnlyFlag = "download-only"
6769
6870 requiredFlags = []string {
6971 orgFlag ,
@@ -136,6 +138,13 @@ func init() {
136138 "local directory for releases to be downloaded to" ,
137139 )
138140
141+ rootCmd .PersistentFlags ().BoolVar (
142+ & opts .downloadOnly ,
143+ downloadOnlyFlag ,
144+ false ,
145+ "only download the releases, do not push them to GCS. Requires the output-dir flag to also be set" ,
146+ )
147+
139148 rootCmd .PersistentFlags ().StringVar (
140149 & opts .logLevel ,
141150 "log-level" ,
@@ -197,9 +206,12 @@ func run(opts *options) error {
197206 if err := gh2gcs .DownloadReleases (& rc , gh , opts .outputDir ); err != nil {
198207 return errors .Wrap (err , "downloading release assets" )
199208 }
209+ logrus .Infof ("Files downloaded to %s folder" , opts .outputDir )
200210
201- if err := gh2gcs .Upload (& rc , gh , opts .outputDir ); err != nil {
202- return errors .Wrap (err , "uploading release assets to GCS" )
211+ if ! opts .downloadOnly {
212+ if err := gh2gcs .Upload (& rc , gh , opts .outputDir ); err != nil {
213+ return errors .Wrap (err , "uploading release assets to GCS" )
214+ }
203215 }
204216 }
205217
@@ -211,6 +223,10 @@ func (o *options) SetAndValidate() error {
211223 logrus .Info ("Validating gh2gcs options..." )
212224
213225 if o .outputDir == "" {
226+ if opts .downloadOnly {
227+ return errors .Errorf ("when %s flag is set you need to specify the %s" , downloadOnlyFlag , outputDirFlag )
228+ }
229+
214230 tmpDir , err := ioutil .TempDir ("" , "gh2gcs" )
215231 if err != nil {
216232 return errors .Wrap (err , "creating temp directory" )
0 commit comments