-
Notifications
You must be signed in to change notification settings - Fork 4
/
list.go
61 lines (49 loc) · 1.53 KB
/
list.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
package endpoint
import (
"os"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
"github.com/fuseml/fuseml-core/pkg/cli/client"
"github.com/fuseml/fuseml-core/pkg/cli/common"
)
type endpointListOptions struct {
client.Clients
global *common.GlobalOptions
format *common.FormattingOptions
}
func newEndpointListOptions(o *common.GlobalOptions) (res *endpointListOptions) {
res = &endpointListOptions{global: o}
res.format = common.NewFormattingOptions(
[]string{"URL", "Type", "Configuration"},
[]table.SortBy{{Name: "URL", Mode: table.Asc}},
common.OutputFormatters{"Configuration": common.FormatMapField},
)
return
}
func newSubCmdEndpointList(gOpt *common.GlobalOptions) *cobra.Command {
o := newEndpointListOptions(gOpt)
cmd := &cobra.Command{
Use: `list {EXTENSION_ID} {SERVICE_ID}`,
Short: "Lists endpoints",
Long: `Display information about the endpoints configured for an extension service.`,
Run: func(cmd *cobra.Command, args []string) {
common.CheckErr(o.InitializeClients(gOpt.URL, gOpt.Timeout, gOpt.Verbose))
common.CheckErr(o.validate())
common.CheckErr(o.run(cmd.Flags().Arg(0), cmd.Flags().Arg(1)))
},
Args: cobra.ExactArgs(2),
}
o.format.AddMultiValueFormattingFlags(cmd)
return cmd
}
func (o *endpointListOptions) validate() error {
return nil
}
func (o *endpointListOptions) run(extensionID, serviceID string) error {
eps, err := o.ExtensionClient.ListEndpoints(extensionID, serviceID)
if err != nil {
return err
}
o.format.FormatValue(os.Stdout, eps)
return nil
}