@@ -3,7 +3,6 @@ package output
33import (
44 "encoding/json"
55 "fmt"
6- "github.com/google/uuid"
76 "io"
87 "io/ioutil"
98 "math"
@@ -17,6 +16,8 @@ import (
1716 "trickest-cli/types"
1817 "trickest-cli/util"
1918
19+ "github.com/google/uuid"
20+
2021 "github.com/schollz/progressbar/v3"
2122 "github.com/spf13/cobra"
2223 "gopkg.in/yaml.v3"
3637 configFile string
3738 allRuns bool
3839 numberOfRuns int
40+ runID string
3941)
4042
4143// OutputCmd represents the download command
@@ -117,17 +119,27 @@ The YAML config file should be formatted like:
117119 if allRuns {
118120 numberOfRuns = math .MaxInt
119121 }
120- wfRuns := GetRuns (workflow .ID , numberOfRuns )
121- if wfRuns != nil && len (wfRuns ) > 0 {
122- runs = append (runs , wfRuns ... )
122+ if runID == "" {
123+ wfRuns := GetRuns (workflow .ID , numberOfRuns )
124+ if wfRuns != nil && len (wfRuns ) > 0 {
125+ runs = append (runs , wfRuns ... )
126+ } else {
127+ fmt .Println ("This workflow has not been executed yet!" )
128+ return
129+ }
123130 } else {
124- fmt .Println ("This workflow has not been executed yet!" )
125- return
131+ runUUID , err := uuid .Parse (runID )
132+ if err != nil {
133+ fmt .Println ("Invalid run ID" )
134+ return
135+ }
136+ run := GetRunByID (runUUID )
137+ runs = []types.Run {* run }
126138 }
127139
128- if numberOfRuns == 1 && (wfRuns [0 ].Status == "SCHEDULED" || wfRuns [0 ].CreationType == types .RunCreationScheduled ) {
129- wfRuns = GetRuns (workflow .ID , numberOfRuns + 1 )
130- runs = append (runs , wfRuns ... )
140+ if numberOfRuns == 1 && (runs [0 ].Status == "SCHEDULED" || runs [0 ].CreationType == types .RunCreationScheduled ) {
141+ runs = GetRuns (workflow .ID , numberOfRuns + 1 )
142+ runs = append (runs , runs ... )
131143 }
132144
133145 version := GetWorkflowVersionByID (runs [0 ].WorkflowVersionInfo )
@@ -148,6 +160,7 @@ func init() {
148160 OutputCmd .Flags ().StringVar (& configFile , "config" , "" , "YAML file to determine which nodes output(s) should be downloaded" )
149161 OutputCmd .Flags ().BoolVar (& allRuns , "all" , false , "Download output data for all runs" )
150162 OutputCmd .Flags ().IntVar (& numberOfRuns , "runs" , 1 , "Number of recent runs which outputs should be downloaded" )
163+ OutputCmd .Flags ().StringVar (& runID , "run" , "" , "Download output data of a specific run" )
151164}
152165
153166func DownloadRunOutput (run * types.Run , nodes map [string ]NodeInfo , version * types.WorkflowVersionDetailed , destinationPath string ) {
@@ -443,6 +456,27 @@ func getSubJobOutput(savePath string, subJob *types.SubJob, fetchData bool) []ty
443456 return subJobOutputs .Results
444457}
445458
459+ func GetRunByID (id uuid.UUID ) * types.Run {
460+ resp := request .Trickest .Get ().DoF ("run/%s/" , id )
461+ if resp == nil {
462+ fmt .Println ("Error: Couldn't get run!" )
463+ os .Exit (0 )
464+ }
465+
466+ if resp .Status () != http .StatusOK {
467+ request .ProcessUnexpectedResponse (resp )
468+ }
469+
470+ var run types.Run
471+ err := json .Unmarshal (resp .Body (), & run )
472+ if err != nil {
473+ fmt .Println ("Error unmarshalling run response!" )
474+ return nil
475+ }
476+
477+ return & run
478+ }
479+
446480func getSubJobs (runID uuid.UUID ) []types.SubJob {
447481 if runID == uuid .Nil {
448482 fmt .Println ("Couldn't list sub-jobs, no run ID parameter specified!" )
0 commit comments