-
Notifications
You must be signed in to change notification settings - Fork 16
/
listfiles.go
56 lines (48 loc) · 1.32 KB
/
listfiles.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
package apit
import (
"context"
"fmt"
"github.com/spf13/cobra"
"golang.org/x/text/cases"
"golang.org/x/text/language"
cmds "github.com/saucelabs/saucectl/internal/cmd"
"github.com/saucelabs/saucectl/internal/http"
"github.com/saucelabs/saucectl/internal/segment"
"github.com/saucelabs/saucectl/internal/usage"
)
func ListFilesCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list-files [--project PROJECT_NAME]",
Short: "List vault files",
Long: `Get a list of files from a project's vault.
Use [--project] to specify the project by its name or run without [--project] to choose from a list of projects.
`,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
err := http.CheckProxy()
if err != nil {
return fmt.Errorf("invalid HTTP_PROXY value")
}
tracker := segment.DefaultTracker
go func() {
tracker.Collect(
cases.Title(language.English).String(cmds.FullName(cmd)),
usage.Properties{}.SetFlags(cmd.Flags()),
)
_ = tracker.Close()
}()
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
files, err := apitesterClient.ListVaultFiles(context.Background(), selectedProject.ID)
if err != nil {
return err
}
for _, file := range files {
fmt.Printf("%s\n", file.Name)
}
return nil
},
}
return cmd
}