Skip to content
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
3 changes: 1 addition & 2 deletions cmd/cli/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sort"
"strconv"

"github.com/docker/cli/cli-plugins/hooks"
"github.com/docker/model-runner/cmd/cli/commands/completion"
"github.com/docker/model-runner/cmd/cli/desktop"
"github.com/docker/model-runner/cmd/cli/pkg/standalone"
Expand Down Expand Up @@ -63,7 +62,7 @@ func textStatus(cmd *cobra.Command, status desktop.Status, backendStatus map[str
cmd.Print(backendStatusTable(backendStatus))
} else {
cmd.Println("Docker Model Runner is not running")
hooks.PrintNextSteps(cmd.OutOrStdout(), []string{enableViaCLI, enableViaGUI})
printNextSteps(cmd.OutOrStdout(), []string{enableViaCLI, enableViaGUI})
osExit(1)
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cli/commands/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"
"testing"

"github.com/docker/cli/cli-plugins/hooks"
"github.com/docker/model-runner/cmd/cli/desktop"
mockdesktop "github.com/docker/model-runner/cmd/cli/mocks"
"github.com/docker/model-runner/cmd/cli/pkg/standalone"
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestStatus(t *testing.T) {
expectedOutput: func() string {
buf := new(bytes.Buffer)
fmt.Fprintln(buf, "Docker Model Runner is not running")
hooks.PrintNextSteps(buf, []string{enableViaCLI, enableViaGUI})
printNextSteps(buf, []string{enableViaCLI, enableViaGUI})
return buf.String()
}(),
},
Expand Down
19 changes: 16 additions & 3 deletions cmd/cli/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"strings"

"github.com/docker/cli/cli-plugins/hooks"
"github.com/docker/model-runner/cmd/cli/desktop"
"github.com/docker/model-runner/cmd/cli/pkg/standalone"
"github.com/docker/model-runner/pkg/distribution/oci/reference"
Expand Down Expand Up @@ -47,12 +46,12 @@ func handleClientError(err error, message string) error {
if errors.Is(err, desktop.ErrServiceUnavailable) {
err = errNotRunning
var buf bytes.Buffer
hooks.PrintNextSteps(&buf, []string{enableViaCLI, enableViaGUI})
printNextSteps(&buf, []string{enableViaCLI, enableViaGUI})
return fmt.Errorf("%w\n%s", err, strings.TrimRight(buf.String(), "\n"))
} else if strings.Contains(err.Error(), vllm.ErrorNotFound.Error()) {
// Handle `run` error.
var buf bytes.Buffer
hooks.PrintNextSteps(&buf, []string{enableVLLM})
printNextSteps(&buf, []string{enableVLLM})
return fmt.Errorf("%w\n%s", err, strings.TrimRight(buf.String(), "\n"))
}
return fmt.Errorf("%s: %w", message, err)
Expand Down Expand Up @@ -270,3 +269,17 @@ func newTable(w io.Writer) *tablewriter.Table {
}),
)
}

func printNextSteps(out io.Writer, messages []string) {
if len(messages) == 0 {
return
}
_, _ = fmt.Fprintln(out, bold("\nWhat's next:"))
for _, n := range messages {
_, _ = fmt.Fprintln(out, " ", n)
}
}
Comment on lines +273 to +281
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The bold function unconditionally adds ANSI escape codes. This is problematic when printNextSteps is called with a non-terminal writer, such as a buffer for an error message in handleClientError. The resulting error string would contain raw escape codes, which can interfere with logging and error parsing.

To address this, printNextSteps should detect if its output writer is a terminal and only apply bold styling when it is. This ensures clean output for both terminal and non-terminal destinations.

Suggested change
func printNextSteps(out io.Writer, messages []string) {
if len(messages) == 0 {
return
}
_, _ = fmt.Fprintln(out, bold("\nWhat's next:"))
for _, n := range messages {
_, _ = fmt.Fprintln(out, " ", n)
}
}
func printNextSteps(out io.Writer, messages []string) {
if len(messages) == 0 {
return
}
isTerminal := false
if f, ok := out.(*os.File); ok {
_, isTerminal = term.GetFdInfo(f)
}
header := "\nWhat's next:"
if isTerminal {
header = bold(header)
}
_, _ = fmt.Fprintln(out, header)
for _, n := range messages {
_, _ = fmt.Fprintln(out, " ", n)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a straight replacement of the existing implementation (but cutting the aec dependency out as intermediate).

Having it as a local implementation would also for enhancements like this, but currently it's just a swap of the code.


func bold(s string) string {
return "\033[1m" + s + "\033[0m"
}
Loading