Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: display the correct response for coder list#16547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
evgeniy-scherbina merged 2 commits intomainfrom16312-coder-cli
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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: 6 additions & 0 deletionscli/cliui/output.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,6 +83,12 @@ func (f *OutputFormatter) Format(ctx context.Context, data any) (string, error)
return "", xerrors.Errorf("unknown output format %q", f.formatID)
}

// FormatID will return the ID of the format selected by `--output`.
// If no flag is present, it returns the 'default' formatter.
func (f *OutputFormatter) FormatID() string {
return f.formatID
}

type tableFormat struct {
defaultColumns []string
allColumns []string
Expand Down
2 changes: 1 addition & 1 deletioncli/list.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,7 +112,7 @@ func (r *RootCmd) list() *serpent.Command {
return err
}

if len(res) == 0 {
if len(res) == 0&& formatter.FormatID() != cliui.JSONFormat().ID(){
pretty.Fprintf(inv.Stderr, cliui.DefaultStyles.Prompt, "No workspaces found! Create one:\n")
_, _ = fmt.Fprintln(inv.Stderr)
_, _ = fmt.Fprintln(inv.Stderr, " "+pretty.Sprint(cliui.DefaultStyles.Code, "coder create <name>"))
Expand Down
26 changes: 26 additions & 0 deletionscli/list_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,4 +74,30 @@ func TestList(t *testing.T) {
require.NoError(t, json.Unmarshal(out.Bytes(), &workspaces))
require.Len(t, workspaces, 1)
})

t.Run("NoWorkspacesJSON", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
owner := coderdtest.CreateFirstUser(t, client)
member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)

inv, root := clitest.New(t, "list", "--output=json")
clitest.SetupConfig(t, member, root)

ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancelFunc()

stdout := bytes.NewBuffer(nil)
stderr := bytes.NewBuffer(nil)
inv.Stdout = stdout
inv.Stderr = stderr
err := inv.WithContext(ctx).Run()
require.NoError(t, err)

var workspaces []codersdk.Workspace
require.NoError(t, json.Unmarshal(stdout.Bytes(), &workspaces))
require.Len(t, workspaces, 0)

require.Len(t, stderr.Bytes(), 0)
})
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp