-
Notifications
You must be signed in to change notification settings - Fork 17
/
get.go
59 lines (51 loc) · 1.42 KB
/
get.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
package apit
import (
"context"
"encoding/json"
"fmt"
"os"
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"
"github.com/spf13/cobra"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func GetCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "get [--project PROJECT_NAME]",
Short: "Get the entire vault contents",
Long: `Print the vault contents as json to stdout.
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 {
vault, err := apitesterClient.GetVault(context.Background(), selectedProject.Hooks[0].Identifier)
if err != nil {
return err
}
err = json.NewEncoder(os.Stdout).Encode(vault)
if err != nil {
return fmt.Errorf("failed to convert vault to json: %w", err)
}
return nil
},
}
return cmd
}