@@ -30,6 +30,7 @@ type FetchOptions struct {
3030 ReleaseAsset string
3131 ReleaseAssetChecksums map [string ]bool
3232 ReleaseAssetChecksumAlgo string
33+ Stdout bool
3334 LocalDownloadPath string
3435 GithubApiVersion string
3536 WithProgress bool
@@ -53,6 +54,7 @@ const optionSourcePath = "source-path"
5354const optionReleaseAsset = "release-asset"
5455const optionReleaseAssetChecksum = "release-asset-checksum"
5556const optionReleaseAssetChecksumAlgo = "release-asset-checksum-algo"
57+ const optionStdout = "stdout"
5658const optionGithubAPIVersion = "github-api-version"
5759const optionWithProgress = "progress"
5860const optionLogLevel = "log-level"
@@ -117,6 +119,10 @@ func CreateFetchCli(version string, writer io.Writer, errwriter io.Writer) *cli.
117119 Name : optionReleaseAssetChecksumAlgo ,
118120 Usage : "The algorithm Fetch will use to compute a checksum of the release asset. Acceptable values\n \t are \" sha256\" and \" sha512\" ." ,
119121 },
122+ cli.StringFlag {
123+ Name : optionStdout ,
124+ Usage : "If \" true\" , the contents of the release asset is sent to standard output so it can be piped to another command." ,
125+ },
120126 cli.StringFlag {
121127 Name : optionGithubAPIVersion ,
122128 Value : "v3" ,
@@ -250,6 +256,25 @@ func runFetch(c *cli.Context, logger *logrus.Logger) error {
250256 }
251257 }
252258
259+ if options .Stdout {
260+ // Print to stdout only if a single asset was downloaded
261+ if len (assetPaths ) == 1 {
262+ dat , err := os .ReadFile (assetPaths [0 ])
263+ if err != nil {
264+ return err
265+ }
266+ c .App .Writer .Write (dat ) // This should be stdout
267+ } else {
268+
269+ if len (assetPaths ) > 1 {
270+ logger .Warn ("Multiple assets were downloaded. Ignoring --stdout" )
271+ } else {
272+ logger .Warn ("No assets were downloaded. Ignoring --stdout" )
273+ }
274+
275+ }
276+ }
277+
253278 return nil
254279}
255280
@@ -282,6 +307,7 @@ func parseOptions(c *cli.Context, logger *logrus.Logger) FetchOptions {
282307 ReleaseAsset : c .String (optionReleaseAsset ),
283308 ReleaseAssetChecksums : assetChecksumMap ,
284309 ReleaseAssetChecksumAlgo : c .String (optionReleaseAssetChecksumAlgo ),
310+ Stdout : c .String (optionStdout ) == "true" ,
285311 LocalDownloadPath : localDownloadPath ,
286312 GithubApiVersion : c .String (optionGithubAPIVersion ),
287313 WithProgress : c .IsSet (optionWithProgress ),
0 commit comments