fix: display the correct response for coder list (#16547)

Closes https://github.com/coder/coder/issues/16312

We intend to modify the behavior of the CLI handler based on the
specified output format. However, the output format is currently only
accessible within the `OutputFormatter` structure. Therefore, I propose
extending `OutputFormatter` by introducing a public `FormatID` method,
which will allow us to retrieve the format identifier and use it to
customize the behavior of the CLI handler accordingly.
This commit is contained in:
Yevhenii Shcherbina
2025-02-13 10:13:20 -05:00
committed by GitHub
parent d52d2397ea
commit 981cf8c333
3 changed files with 33 additions and 1 deletions
+1 -1
View File
@@ -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>"))