-
Notifications
You must be signed in to change notification settings - Fork 0
/
location.go
55 lines (42 loc) · 1.34 KB
/
location.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
package common
import (
"github.com/spf13/cobra"
"github.com/flowswiss/cli/v2/internal/commands"
"github.com/flowswiss/cli/v2/pkg/api/common"
"github.com/flowswiss/cli/v2/pkg/filter"
)
func Location(app commands.Application) *cobra.Command {
cmd := &cobra.Command{
Use: "location",
Short: "Manage datacenter locations",
}
commands.Add(app, cmd, &locationListCommand{})
return cmd
}
type locationListCommand struct {
filter string
}
func (l *locationListCommand) Run(cmd *cobra.Command, args []string) (err error) {
items, err := common.Locations(cmd.Context(), commands.Config.Client)
if err != nil {
return err
}
if len(l.filter) != 0 {
items = filter.Find(items, l.filter)
}
return commands.PrintStdout(items)
}
func (l *locationListCommand) CompleteArg(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
}
func (l *locationListCommand) Build(app commands.Application) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List datacenter locations",
Long: "Lists all datacenter locations including their available modules.",
ValidArgsFunction: l.CompleteArg,
RunE: l.Run,
}
cmd.Flags().StringVar(&l.filter, "filter", "", "custom term to filter the results")
return cmd
}