/
get.go
73 lines (59 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cmd
import (
"context"
"fmt"
"os"
"github.com/ghdwlsgur/outline-vpn/internal"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
)
func getAccessURL() error {
ctx := context.Background()
list, err := internal.ValidateOutlineJson(ctx, terraformVersion, _defaultTerraformPath)
if err != nil {
return err
}
answer, err := internal.AskPromptOptionList("Choose a Workspace (Region):", list, 10)
if err != nil {
return err
}
accessKeys, err := internal.GetAccessKeys(answer)
if err != nil {
return err
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
if len(accessKeys.Keys) > 0 {
t.AppendHeader(table.Row{"ID", "AccessURL", "Password", "Region"})
for _, v := range accessKeys.Keys {
t.AppendRow(table.Row{v.ID, v.AccessURL, v.Password, answer})
}
} else {
fmt.Println("The access key does not exist")
}
t.Render()
return nil
}
var (
getCommand = &cobra.Command{
Use: "get",
Short: "Retrieving the outline resources",
Long: "Retrieving the outline resources",
ValidArgs: []string{"accesskey"},
Args: cobra.MatchAll(internal.WrapArgsError(cobra.MinimumNArgs(1)), cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(_ *cobra.Command, args []string) {
var (
err error
)
switch args[0] {
case "accesskey":
if getAccessURL(); err != nil {
panicRed(err)
}
}
},
}
)
func init() {
rootCmd.AddCommand(getCommand)
}