MCPcopy Index your code
hub / github.com/coder/coder / featuresList

Method featuresList

enterprise/cli/features.go:33–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31}
32
33func (r *RootCmd) featuresList() *serpent.Command {
34 var (
35 featureColumns = []string{"name", "entitlement", "enabled", "limit", "actual"}
36 columns []string
37 outputFormat string
38 )
39
40 cmd := &serpent.Command{
41 Use: "list",
42 Aliases: []string{"ls"},
43 Middleware: serpent.Chain(),
44 Handler: func(inv *serpent.Invocation) error {
45 client, err := r.InitClient(inv)
46 if err != nil {
47 return err
48 }
49 entitlements, err := client.Entitlements(inv.Context())
50 var apiError *codersdk.Error
51 if errors.As(err, &apiError) && apiError.StatusCode() == http.StatusNotFound {
52 return xerrors.New("You are on the AGPL licensed version of Coder that does not have Enterprise functionality!")
53 }
54 if err != nil {
55 return err
56 }
57
58 // This uses custom formatting as the JSON output outputs an object
59 // as opposed to a list from the table output.
60 out := ""
61 switch outputFormat {
62 case "table", "":
63 out, err = displayFeatures(columns, entitlements.Features)
64 if err != nil {
65 return xerrors.Errorf("render table: %w", err)
66 }
67 case "json":
68 buf := new(bytes.Buffer)
69 enc := json.NewEncoder(buf)
70 enc.SetIndent("", " ")
71 err = enc.Encode(entitlements)
72 if err != nil {
73 return xerrors.Errorf("marshal features to JSON: %w", err)
74 }
75 out = buf.String()
76 default:
77 return xerrors.Errorf(`unknown output format %q, only "table" and "json" are supported`, outputFormat)
78 }
79
80 _, err = fmt.Fprintln(inv.Stdout, out)
81 return err
82 },
83 }
84
85 cmd.Options = serpent.OptionSet{
86 {
87 Flag: "column",
88 FlagShorthand: "c",
89 Description: "Specify columns to filter in the table.",
90 Default: strings.Join(featureColumns, ","),

Callers 1

featuresMethod · 0.95

Calls 10

InitClientMethod · 0.95
StatusCodeMethod · 0.95
displayFeaturesFunction · 0.85
EntitlementsMethod · 0.80
AsMethod · 0.80
EncodeMethod · 0.80
ContextMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected