diff --git a/.golangci.yml b/.golangci.yml index aa56dabb..193ab2b8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,6 +12,6 @@ linters-settings: settings: printf: funcs: # Run `go tool vet help printf` to see available settings for `printf` analyzer. - - (cdr.dev/coder-cli/internal/clog).Tipf - - (cdr.dev/coder-cli/internal/clog).Hintf - - (cdr.dev/coder-cli/internal/clog).Causef \ No newline at end of file + - (cdr.dev/coder-cli/pkg/clog).Tipf + - (cdr.dev/coder-cli/pkg/clog).Hintf + - (cdr.dev/coder-cli/pkg/clog).Causef \ No newline at end of file diff --git a/ci/integration/devurls_test.go b/ci/integration/devurls_test.go index 6dee8211..315d122e 100644 --- a/ci/integration/devurls_test.go +++ b/ci/integration/devurls_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "cdr.dev/coder-cli/ci/tcli" + "cdr.dev/coder-cli/pkg/tcli" ) func TestDevURLCLI(t *testing.T) { diff --git a/ci/integration/envs_test.go b/ci/integration/envs_test.go index 075f7222..76138c6d 100644 --- a/ci/integration/envs_test.go +++ b/ci/integration/envs_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "cdr.dev/coder-cli/ci/tcli" "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog" "cdr.dev/slog/sloggers/slogtest" "cdr.dev/slog/sloggers/slogtest/assert" diff --git a/ci/integration/integration_test.go b/ci/integration/integration_test.go index 8475de4f..1fc644e4 100644 --- a/ci/integration/integration_test.go +++ b/ci/integration/integration_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "cdr.dev/coder-cli/ci/tcli" + "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog/sloggers/slogtest/assert" ) diff --git a/ci/integration/secrets_test.go b/ci/integration/secrets_test.go index fadcc84e..7d3b6663 100644 --- a/ci/integration/secrets_test.go +++ b/ci/integration/secrets_test.go @@ -6,7 +6,7 @@ import ( "regexp" "testing" - "cdr.dev/coder-cli/ci/tcli" + "cdr.dev/coder-cli/pkg/tcli" ) func TestSecrets(t *testing.T) { diff --git a/ci/integration/setup_test.go b/ci/integration/setup_test.go index 1919f6a0..1ccb8e0e 100644 --- a/ci/integration/setup_test.go +++ b/ci/integration/setup_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "cdr.dev/coder-cli/ci/tcli" + "cdr.dev/coder-cli/pkg/tcli" "golang.org/x/xerrors" ) diff --git a/ci/integration/ssh_test.go b/ci/integration/ssh_test.go index 3882b719..6a084a0d 100644 --- a/ci/integration/ssh_test.go +++ b/ci/integration/ssh_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "cdr.dev/coder-cli/ci/tcli" "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/pkg/tcli" ) func TestSSH(t *testing.T) { diff --git a/ci/integration/users_test.go b/ci/integration/users_test.go index 55d554f2..1272337f 100644 --- a/ci/integration/users_test.go +++ b/ci/integration/users_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "cdr.dev/coder-cli/ci/tcli" "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog/sloggers/slogtest/assert" ) diff --git a/cmd/coder/main.go b/cmd/coder/main.go index d59a1abe..73e1858d 100644 --- a/cmd/coder/main.go +++ b/cmd/coder/main.go @@ -9,10 +9,10 @@ import ( "os" "runtime" - "cdr.dev/coder-cli/internal/clog" "cdr.dev/coder-cli/internal/cmd" "cdr.dev/coder-cli/internal/version" "cdr.dev/coder-cli/internal/x/xterminal" + "cdr.dev/coder-cli/pkg/clog" ) func main() { diff --git a/coder-sdk/devurl.go b/coder-sdk/devurl.go index e5c387e6..a288d418 100644 --- a/coder-sdk/devurl.go +++ b/coder-sdk/devurl.go @@ -8,11 +8,11 @@ import ( // DevURL is the parsed json response record for a devURL from cemanager. type DevURL struct { - ID string `json:"id" tab:"ID"` - URL string `json:"url" tab:"URL"` - Port int `json:"port" tab:"Port"` - Access string `json:"access" tab:"Access"` - Name string `json:"name" tab:"Name"` + ID string `json:"id" table:"ID"` + URL string `json:"url" table:"URL"` + Port int `json:"port" table:"Port"` + Access string `json:"access" table:"Access"` + Name string `json:"name" table:"Name"` } type delDevURLRequest struct { diff --git a/coder-sdk/env.go b/coder-sdk/env.go index a95ed4bf..a15f1caa 100644 --- a/coder-sdk/env.go +++ b/coder-sdk/env.go @@ -13,32 +13,32 @@ import ( // Environment describes a Coder environment type Environment struct { - ID string `json:"id" tab:"-"` - Name string `json:"name" tab:"Name"` - ImageID string `json:"image_id" tab:"-"` - ImageTag string `json:"image_tag" tab:"ImageTag"` - OrganizationID string `json:"organization_id" tab:"-"` - UserID string `json:"user_id" tab:"-"` - LastBuiltAt time.Time `json:"last_built_at" tab:"-"` - CPUCores float32 `json:"cpu_cores" tab:"CPUCores"` - MemoryGB float32 `json:"memory_gb" tab:"MemoryGB"` - DiskGB int `json:"disk_gb" tab:"DiskGB"` - GPUs int `json:"gpus" tab:"GPUs"` - Updating bool `json:"updating" tab:"Updating"` - LatestStat EnvironmentStat `json:"latest_stat" tab:"Status"` - RebuildMessages []RebuildMessage `json:"rebuild_messages" tab:"-"` - CreatedAt time.Time `json:"created_at" tab:"-"` - UpdatedAt time.Time `json:"updated_at" tab:"-"` - LastOpenedAt time.Time `json:"last_opened_at" tab:"-"` - LastConnectionAt time.Time `json:"last_connection_at" tab:"-"` - AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" tab:"-"` + ID string `json:"id" table:"-"` + Name string `json:"name" table:"Name"` + ImageID string `json:"image_id" table:"-"` + ImageTag string `json:"image_tag" table:"ImageTag"` + OrganizationID string `json:"organization_id" table:"-"` + UserID string `json:"user_id" table:"-"` + LastBuiltAt time.Time `json:"last_built_at" table:"-"` + CPUCores float32 `json:"cpu_cores" table:"CPUCores"` + MemoryGB float32 `json:"memory_gb" table:"MemoryGB"` + DiskGB int `json:"disk_gb" table:"DiskGB"` + GPUs int `json:"gpus" table:"GPUs"` + Updating bool `json:"updating" table:"Updating"` + LatestStat EnvironmentStat `json:"latest_stat" table:"Status"` + RebuildMessages []RebuildMessage `json:"rebuild_messages" table:"-"` + CreatedAt time.Time `json:"created_at" table:"-"` + UpdatedAt time.Time `json:"updated_at" table:"-"` + LastOpenedAt time.Time `json:"last_opened_at" table:"-"` + LastConnectionAt time.Time `json:"last_connection_at" table:"-"` + AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" table:"-"` } // RebuildMessage defines the message shown when an Environment requires a rebuild for it can be accessed. type RebuildMessage struct { Text string `json:"text"` Required bool `json:"required"` - AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" tab:"-"` + AutoOffThreshold xjson.MSDuration `json:"auto_off_threshold" table:"-"` } // EnvironmentStat represents the state of an environment diff --git a/coder-sdk/secrets.go b/coder-sdk/secrets.go index 21a1583b..cb5c1535 100644 --- a/coder-sdk/secrets.go +++ b/coder-sdk/secrets.go @@ -8,12 +8,12 @@ import ( // Secret describes a Coder secret type Secret struct { - ID string `json:"id" tab:"-"` - Name string `json:"name" tab:"Name"` - Value string `json:"value,omitempty" tab:"Value"` - Description string `json:"description" tab:"Description"` - CreatedAt time.Time `json:"created_at" tab:"CreatedAt"` - UpdatedAt time.Time `json:"updated_at" tab:"-"` + ID string `json:"id" table:"-"` + Name string `json:"name" table:"Name"` + Value string `json:"value,omitempty" table:"Value"` + Description string `json:"description" table:"Description"` + CreatedAt time.Time `json:"created_at" table:"CreatedAt"` + UpdatedAt time.Time `json:"updated_at" table:"-"` } // Secrets gets all secrets for the given user diff --git a/coder-sdk/users.go b/coder-sdk/users.go index 1008f38b..e988a697 100644 --- a/coder-sdk/users.go +++ b/coder-sdk/users.go @@ -8,12 +8,12 @@ import ( // User describes a Coder user account. type User struct { - ID string `json:"id" tab:"-"` - Email string `json:"email" tab:"Email"` - Username string `json:"username" tab:"Username"` - Name string `json:"name" tab:"Name"` - CreatedAt time.Time `json:"created_at" tab:"CreatedAt"` - UpdatedAt time.Time `json:"updated_at" tab:"-"` + ID string `json:"id" table:"-"` + Email string `json:"email" table:"Email"` + Username string `json:"username" table:"Username"` + Name string `json:"name" table:"Name"` + CreatedAt time.Time `json:"created_at" table:"CreatedAt"` + UpdatedAt time.Time `json:"updated_at" table:"-"` } // Me gets the details of the authenticated user. diff --git a/internal/activity/pusher.go b/internal/activity/pusher.go index 6d0a224f..e54786e7 100644 --- a/internal/activity/pusher.go +++ b/internal/activity/pusher.go @@ -8,7 +8,7 @@ import ( "golang.org/x/time/rate" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" + "cdr.dev/coder-cli/pkg/clog" ) const pushInterval = time.Minute diff --git a/internal/cmd/auth.go b/internal/cmd/auth.go index 1860298d..b517abc6 100644 --- a/internal/cmd/auth.go +++ b/internal/cmd/auth.go @@ -9,9 +9,9 @@ import ( "golang.org/x/xerrors" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" "cdr.dev/coder-cli/internal/config" "cdr.dev/coder-cli/internal/version" + "cdr.dev/coder-cli/pkg/clog" ) var errNeedLogin = clog.Fatal( diff --git a/internal/cmd/ceapi.go b/internal/cmd/ceapi.go index e453cbae..3d91c176 100644 --- a/internal/cmd/ceapi.go +++ b/internal/cmd/ceapi.go @@ -6,7 +6,7 @@ import ( "strings" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" + "cdr.dev/coder-cli/pkg/clog" "golang.org/x/xerrors" ) diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index 8805e208..5b75028e 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -7,8 +7,8 @@ import ( "os" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" - "cdr.dev/coder-cli/internal/x/xtabwriter" + "cdr.dev/coder-cli/pkg/clog" + "cdr.dev/coder-cli/pkg/tablewriter" "github.com/manifoldco/promptui" "github.com/spf13/cobra" @@ -62,7 +62,7 @@ func lsEnvsCommand(user *string) *cobra.Command { switch outputFmt { case "human": - err := xtabwriter.WriteTable(len(envs), func(i int) interface{} { + err := tablewriter.WriteTable(len(envs), func(i int) interface{} { return envs[i] }) if err != nil { diff --git a/internal/cmd/login.go b/internal/cmd/login.go index d6a8db11..38a34982 100644 --- a/internal/cmd/login.go +++ b/internal/cmd/login.go @@ -9,9 +9,9 @@ import ( "strings" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" "cdr.dev/coder-cli/internal/config" "cdr.dev/coder-cli/internal/loginsrv" + "cdr.dev/coder-cli/pkg/clog" "github.com/pkg/browser" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" diff --git a/internal/cmd/logout.go b/internal/cmd/logout.go index dde3d758..8c1c27a6 100644 --- a/internal/cmd/logout.go +++ b/internal/cmd/logout.go @@ -3,8 +3,8 @@ package cmd import ( "os" - "cdr.dev/coder-cli/internal/clog" "cdr.dev/coder-cli/internal/config" + "cdr.dev/coder-cli/pkg/clog" "github.com/spf13/cobra" "golang.org/x/xerrors" ) diff --git a/internal/cmd/rebuild.go b/internal/cmd/rebuild.go index 687e132c..ebb1cc8a 100644 --- a/internal/cmd/rebuild.go +++ b/internal/cmd/rebuild.go @@ -8,7 +8,7 @@ import ( "time" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" + "cdr.dev/coder-cli/pkg/clog" "github.com/briandowns/spinner" "github.com/fatih/color" "github.com/manifoldco/promptui" diff --git a/internal/cmd/resourcemanager.go b/internal/cmd/resourcemanager.go index 1fbc210d..2e636d7e 100644 --- a/internal/cmd/resourcemanager.go +++ b/internal/cmd/resourcemanager.go @@ -8,7 +8,7 @@ import ( "text/tabwriter" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" + "cdr.dev/coder-cli/pkg/clog" "github.com/spf13/cobra" "golang.org/x/xerrors" ) diff --git a/internal/cmd/secrets.go b/internal/cmd/secrets.go index 7c8dfdf6..d15e9778 100644 --- a/internal/cmd/secrets.go +++ b/internal/cmd/secrets.go @@ -10,8 +10,8 @@ import ( "golang.org/x/xerrors" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" - "cdr.dev/coder-cli/internal/x/xtabwriter" + "cdr.dev/coder-cli/pkg/clog" + "cdr.dev/coder-cli/pkg/tablewriter" ) func secretsCmd() *cobra.Command { @@ -159,7 +159,7 @@ func listSecretsCmd(userEmail *string) func(cmd *cobra.Command, _ []string) erro return nil } - err = xtabwriter.WriteTable(len(secrets), func(i int) interface{} { + err = tablewriter.WriteTable(len(secrets), func(i int) interface{} { s := secrets[i] s.Value = "******" // value is omitted from bulk responses return s diff --git a/internal/cmd/shell.go b/internal/cmd/shell.go index 7a79a2b7..07904b3e 100644 --- a/internal/cmd/shell.go +++ b/internal/cmd/shell.go @@ -16,8 +16,8 @@ import ( "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/activity" - "cdr.dev/coder-cli/internal/clog" "cdr.dev/coder-cli/internal/x/xterminal" + "cdr.dev/coder-cli/pkg/clog" "cdr.dev/wsep" ) diff --git a/internal/cmd/sync.go b/internal/cmd/sync.go index 9f162b1b..41a24d4e 100644 --- a/internal/cmd/sync.go +++ b/internal/cmd/sync.go @@ -9,8 +9,8 @@ import ( "strings" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" "cdr.dev/coder-cli/internal/sync" + "cdr.dev/coder-cli/pkg/clog" "github.com/spf13/cobra" "golang.org/x/xerrors" ) diff --git a/internal/cmd/urls.go b/internal/cmd/urls.go index fa4ebd0f..ccc8ea93 100644 --- a/internal/cmd/urls.go +++ b/internal/cmd/urls.go @@ -14,8 +14,8 @@ import ( "golang.org/x/xerrors" "cdr.dev/coder-cli/coder-sdk" - "cdr.dev/coder-cli/internal/clog" - "cdr.dev/coder-cli/internal/x/xtabwriter" + "cdr.dev/coder-cli/pkg/clog" + "cdr.dev/coder-cli/pkg/tablewriter" ) func urlCmd() *cobra.Command { @@ -51,11 +51,11 @@ func urlCmd() *cobra.Command { // DevURL is the parsed json response record for a devURL from cemanager type DevURL struct { - ID string `json:"id" tab:"-"` - URL string `json:"url" tab:"URL"` - Port int `json:"port" tab:"Port"` - Name string `json:"name" tab:"-"` - Access string `json:"access" tab:"Access"` + ID string `json:"id" table:"-"` + URL string `json:"url" table:"URL"` + Port int `json:"port" table:"Port"` + Name string `json:"name" table:"-"` + Access string `json:"access" table:"Access"` } var urlAccessLevel = map[string]string{ @@ -104,7 +104,7 @@ func listDevURLsCmd(outputFmt *string) func(cmd *cobra.Command, args []string) e clog.LogInfo(fmt.Sprintf("no devURLs found for environment %q", envName)) return nil } - err := xtabwriter.WriteTable(len(devURLs), func(i int) interface{} { + err := tablewriter.WriteTable(len(devURLs), func(i int) interface{} { return devURLs[i] }) if err != nil { diff --git a/internal/cmd/users.go b/internal/cmd/users.go index 87f40fa4..e200fbbc 100644 --- a/internal/cmd/users.go +++ b/internal/cmd/users.go @@ -4,10 +4,9 @@ import ( "encoding/json" "os" + "cdr.dev/coder-cli/pkg/tablewriter" "github.com/spf13/cobra" "golang.org/x/xerrors" - - "cdr.dev/coder-cli/internal/x/xtabwriter" ) func usersCmd() *cobra.Command { @@ -47,7 +46,7 @@ func listUsers(outputFmt *string) func(cmd *cobra.Command, args []string) error case "human": // For each element, return the user. each := func(i int) interface{} { return users[i] } - if err := xtabwriter.WriteTable(len(users), each); err != nil { + if err := tablewriter.WriteTable(len(users), each); err != nil { return xerrors.Errorf("write table: %w", err) } case "json": diff --git a/internal/sync/sync.go b/internal/sync/sync.go index 177ff9c9..225ec598 100644 --- a/internal/sync/sync.go +++ b/internal/sync/sync.go @@ -23,7 +23,7 @@ import ( "cdr.dev/coder-cli/coder-sdk" "cdr.dev/coder-cli/internal/activity" - "cdr.dev/coder-cli/internal/clog" + "cdr.dev/coder-cli/pkg/clog" "cdr.dev/wsep" ) diff --git a/internal/clog/doc.go b/pkg/clog/doc.go similarity index 82% rename from internal/clog/doc.go rename to pkg/clog/doc.go index 4c1dacaf..9e5717bb 100644 --- a/internal/clog/doc.go +++ b/pkg/clog/doc.go @@ -1,4 +1,4 @@ -// package clog provides rich error types and logging helpers for coder-cli. +// Package clog provides rich error types and logging helpers for coder-cli. // // clog encourages returning error types rather than // logging them and failing with os.Exit as they happen. diff --git a/internal/clog/errgroup.go b/pkg/clog/errgroup.go similarity index 100% rename from internal/clog/errgroup.go rename to pkg/clog/errgroup.go diff --git a/internal/clog/error.go b/pkg/clog/error.go similarity index 100% rename from internal/clog/error.go rename to pkg/clog/error.go diff --git a/pkg/tablewriter/doc.go b/pkg/tablewriter/doc.go new file mode 100644 index 00000000..366a7b9e --- /dev/null +++ b/pkg/tablewriter/doc.go @@ -0,0 +1,2 @@ +// Package tablewriter provides helpers for printing human-readable tabular data from slices of structs. +package tablewriter diff --git a/internal/x/xtabwriter/tabwriter.go b/pkg/tablewriter/tablewriter.go similarity index 75% rename from internal/x/xtabwriter/tabwriter.go rename to pkg/tablewriter/tablewriter.go index 6c28b647..acc2545d 100644 --- a/internal/x/xtabwriter/tabwriter.go +++ b/pkg/tablewriter/tablewriter.go @@ -1,4 +1,4 @@ -package xtabwriter +package tablewriter import ( "fmt" @@ -8,16 +8,11 @@ import ( "text/tabwriter" ) -const structFieldTagKey = "tab" - -// NewWriter chooses reasonable defaults for a human readable output of tabular data. -func NewWriter() *tabwriter.Writer { - return tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0) -} +const structFieldTagKey = "table" // StructValues tab delimits the values of a given struct. // -// Tag a field `tab:"-"` to hide it from output. +// Tag a field `table:"-"` to hide it from output. func StructValues(data interface{}) string { v := reflect.ValueOf(data) s := &strings.Builder{} @@ -32,7 +27,7 @@ func StructValues(data interface{}) string { // StructFieldNames tab delimits the field names of a given struct. // -// Tag a field `tab:"-"` to hide it from output. +// Tag a field `table:"-"` to hide it from output. func StructFieldNames(data interface{}) string { v := reflect.ValueOf(data) s := &strings.Builder{} @@ -47,14 +42,14 @@ func StructFieldNames(data interface{}) string { } // WriteTable writes the given list elements to stdout in a human readable -// tabular format. Headers abide by the `tab` struct tag. +// tabular format. Headers abide by the `table` struct tag. // -// `tab:"-"` omits the field and no tag defaults to the Go identifier. +// `table:"-"` omits the field and no tag defaults to the Go identifier. func WriteTable(length int, each func(i int) interface{}) error { if length < 1 { return nil } - w := NewWriter() + w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0) defer func() { _ = w.Flush() }() // Best effort. for ix := 0; ix < length; ix++ { item := each(ix) diff --git a/ci/tcli/doc.go b/pkg/tcli/doc.go similarity index 100% rename from ci/tcli/doc.go rename to pkg/tcli/doc.go diff --git a/ci/tcli/tcli.go b/pkg/tcli/tcli.go similarity index 100% rename from ci/tcli/tcli.go rename to pkg/tcli/tcli.go diff --git a/ci/tcli/tcli_test.go b/pkg/tcli/tcli_test.go similarity index 97% rename from ci/tcli/tcli_test.go rename to pkg/tcli/tcli_test.go index 97bd1b6e..5ecce5f0 100644 --- a/ci/tcli/tcli_test.go +++ b/pkg/tcli/tcli_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "cdr.dev/coder-cli/ci/tcli" + "cdr.dev/coder-cli/pkg/tcli" "cdr.dev/slog/sloggers/slogtest/assert" )
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: