mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
* fix: Add coder user to docker group on installation This makes for a simpler setup, and reduces the likelihood a user runs into a strange issue. * Add wgnet * Add ping * Add listening * Finish refactor to make this work * Add interface for swapping * Fix conncache with interface * chore: update gvisor * fix tailscale types * linting * more linting * Add coordinator * Add coordinator tests * Fix coordination * It compiles! * Move all connection negotiation in-memory * Migrate coordinator to use net.conn * Add closed func * Fix close listener func * Make reconnecting PTY work * Fix reconnecting PTY * Update CI to Go 1.19 * Add CLI flags for DERP mapping * Fix Tailnet test * Rename ConnCoordinator to TailnetCoordinator * Remove print statement from workspace agent test * Refactor wsconncache to use tailnet * Remove STUN from unit tests * Add migrate back to dump * chore: Upgrade to Go 1.19 This is required as part of #3505. * Fix reconnecting PTY tests * fix: update wireguard-go to fix devtunnel * fix migration numbers * linting * Return early for status if endpoints are empty * Update cli/server.go Co-authored-by: Colin Adler <colin1adler@gmail.com> * Update cli/server.go Co-authored-by: Colin Adler <colin1adler@gmail.com> * Fix frontend entites * Fix agent bicopy * Fix race condition for the last node * Fix down migration * Fix connection RBAC * Fix migration numbers * Fix forwarding TCP to a local port * Implement ping for tailnet * Rename to ForceHTTP * Add external derpmapping * Expose DERP region names to the API * Add global option to enable Tailscale networking for web * Mark DERP flags hidden while testing * Update DERP map on reconnect * Add close func to workspace agents * Fix race condition in upstream dependency * Fix feature columns race condition Co-authored-by: Colin Adler <colin1adler@gmail.com>
105 lines
2.6 KiB
Go
105 lines
2.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/cli/cliui"
|
|
"github.com/coder/coder/codersdk"
|
|
)
|
|
|
|
func features() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Short: "List features",
|
|
Use: "features",
|
|
Aliases: []string{"feature"},
|
|
}
|
|
cmd.AddCommand(
|
|
featuresList(),
|
|
)
|
|
return cmd
|
|
}
|
|
|
|
func featuresList() *cobra.Command {
|
|
var (
|
|
featureColumns = []string{"Name", "Entitlement", "Enabled", "Limit", "Actual"}
|
|
columns []string
|
|
outputFormat string
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "list",
|
|
Aliases: []string{"ls"},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client, err := CreateClient(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
entitlements, err := client.Entitlements(cmd.Context())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
out := ""
|
|
switch outputFormat {
|
|
case "table", "":
|
|
out, err = displayFeatures(columns, entitlements.Features)
|
|
if err != nil {
|
|
return xerrors.Errorf("render table: %w", err)
|
|
}
|
|
case "json":
|
|
buf := new(bytes.Buffer)
|
|
enc := json.NewEncoder(buf)
|
|
enc.SetIndent("", " ")
|
|
err = enc.Encode(entitlements)
|
|
if err != nil {
|
|
return xerrors.Errorf("marshal features to JSON: %w", err)
|
|
}
|
|
out = buf.String()
|
|
default:
|
|
return xerrors.Errorf(`unknown output format %q, only "table" and "json" are supported`, outputFormat)
|
|
}
|
|
|
|
_, err = fmt.Fprintln(cmd.OutOrStdout(), out)
|
|
return err
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringArrayVarP(&columns, "column", "c", featureColumns,
|
|
fmt.Sprintf("Specify a column to filter in the table. Available columns are: %s",
|
|
strings.Join(featureColumns, ", ")))
|
|
cmd.Flags().StringVarP(&outputFormat, "output", "o", "table", "Output format. Available formats are: table, json.")
|
|
return cmd
|
|
}
|
|
|
|
type featureRow struct {
|
|
Name string `table:"name"`
|
|
Entitlement string `table:"entitlement"`
|
|
Enabled bool `table:"enabled"`
|
|
Limit *int64 `table:"limit"`
|
|
Actual *int64 `table:"actual"`
|
|
}
|
|
|
|
// displayFeatures will return a table displaying all features passed in.
|
|
// filterColumns must be a subset of the feature fields and will determine which
|
|
// columns to display
|
|
func displayFeatures(filterColumns []string, features map[string]codersdk.Feature) (string, error) {
|
|
rows := make([]featureRow, 0, len(features))
|
|
for name, feat := range features {
|
|
rows = append(rows, featureRow{
|
|
Name: name,
|
|
Entitlement: string(feat.Entitlement),
|
|
Enabled: feat.Enabled,
|
|
Limit: feat.Limit,
|
|
Actual: feat.Actual,
|
|
})
|
|
}
|
|
|
|
return cliui.DisplayTable(rows, "name", filterColumns)
|
|
}
|