Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Restructure go util packages #166

Merged
merged 5 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- (cdr.dev/coder-cli/pkg/clog).Tipf
- (cdr.dev/coder-cli/pkg/clog).Hintf
- (cdr.dev/coder-cli/pkg/clog).Causef
2 changes: 1 addition & 1 deletion ci/integration/devurls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"testing"

"cdr.dev/coder-cli/ci/tcli"
"cdr.dev/coder-cli/pkg/tcli"
)

func TestDevURLCLI(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ci/integration/envs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ci/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion ci/integration/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"testing"

"cdr.dev/coder-cli/ci/tcli"
"cdr.dev/coder-cli/pkg/tcli"
)

func TestSecrets(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ci/integration/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

"cdr.dev/coder-cli/ci/tcli"
"cdr.dev/coder-cli/pkg/tcli"
"golang.org/x/xerrors"
)

Expand Down
2 changes: 1 addition & 1 deletion ci/integration/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ci/integration/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/coder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions coder-sdk/devurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 20 additions & 20 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions coder-sdk/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions coder-sdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/activity/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/ceapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/resourcemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
16 changes: 8 additions & 8 deletions internal/cmd/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/clog/doc.go → pkg/clog/doc.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
Loading