-
Notifications
You must be signed in to change notification settings - Fork 129
/
artifacts.go
87 lines (72 loc) · 2.47 KB
/
artifacts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package artifacts
import (
"fmt"
"os"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/validator"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/tests"
"github.com/kubeshop/testkube/pkg/ui"
"github.com/spf13/cobra"
)
var (
executionID string
filename string
destination string
downloadDir string
)
func NewListArtifactsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "artifact <executionName>",
Aliases: []string{"artifacts"},
Short: "List artifacts of the given execution name",
Args: validator.ExecutionName,
Run: func(cmd *cobra.Command, args []string) {
executionID = args[0]
cmd.SilenceUsage = true
client, _ := common.GetClient(cmd)
artifacts, err := client.GetExecutionArtifacts(executionID)
ui.ExitOnError("getting artifacts ", err)
ui.Table(artifacts, os.Stdout)
},
}
cmd.PersistentFlags().StringVarP(&executionID, "execution-id", "e", "", "ID of the execution")
// output renderer flags
return cmd
}
func NewDownloadSingleArtifactsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "single <executionName> <fileName> <destinationDir>",
Short: "download artifact",
Args: validator.ExecutionIDAndFileNames,
Run: func(cmd *cobra.Command, args []string) {
executionID := args[0]
filename := args[1]
destination := args[2]
client, _ := common.GetClient(cmd)
f, err := client.DownloadFile(executionID, filename, destination)
ui.ExitOnError("downloading file"+filename, err)
ui.Info(fmt.Sprintf("File %s downloaded.\n", f))
},
}
cmd.PersistentFlags().StringVarP(&executionID, "execution-id", "e", "", "ID of the execution")
cmd.PersistentFlags().StringVarP(&filename, "filename", "f", "", "name of the file")
cmd.PersistentFlags().StringVarP(&destination, "destination", "d", "", "name of the file")
// output renderer flags
return cmd
}
func NewDownloadAllArtifactsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "all <executionName>",
Short: "download artifacts",
Args: validator.ExecutionName,
Run: func(cmd *cobra.Command, args []string) {
executionID := args[0]
client, _ := common.GetClient(cmd)
tests.DownloadArtifacts(executionID, downloadDir, client)
},
}
cmd.PersistentFlags().StringVarP(&executionID, "execution-id", "e", "", "ID of the execution")
cmd.Flags().StringVar(&downloadDir, "download-dir", "artifacts", "download dir")
// output renderer flags
return cmd
}