-
Notifications
You must be signed in to change notification settings - Fork 4
Show container start guidance on more commands #168
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gtsiolis
wants to merge
2
commits into
main
Choose a base branch
from
george/des-187
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package output | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/charmbracelet/lipgloss" | ||
| ) | ||
|
|
||
| var ( | ||
| colorErrorTitle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#C33820")) | ||
| colorErrorSecondary = lipgloss.NewStyle().Foreground(lipgloss.Color("241")) | ||
| colorErrorDetail = lipgloss.NewStyle().Foreground(lipgloss.Color("245")) | ||
| colorErrorAction = lipgloss.NewStyle().Foreground(lipgloss.Color("69")) | ||
| colorErrorMuted = lipgloss.NewStyle().Foreground(lipgloss.Color("245")) | ||
| ) | ||
|
|
||
| // FormatColorEventLine is like FormatEventLine but renders ErrorEvent with ANSI color. | ||
| // All other event types delegate to FormatEventLine. | ||
| func FormatColorEventLine(event any) (string, bool) { | ||
| if e, ok := event.(ErrorEvent); ok { | ||
| return formatColorErrorEvent(e), true | ||
| } | ||
| return FormatEventLine(event) | ||
| } | ||
|
|
||
| func formatColorErrorEvent(e ErrorEvent) string { | ||
| var sb strings.Builder | ||
| sb.WriteString(colorErrorTitle.Render("✗ " + e.Title)) | ||
| if e.Summary != "" { | ||
| sb.WriteString("\n") | ||
| sb.WriteString(colorErrorSecondary.Render("> ")) | ||
| sb.WriteString(e.Summary) | ||
| } | ||
| if e.Detail != "" { | ||
| sb.WriteString("\n ") | ||
| sb.WriteString(colorErrorDetail.Render(e.Detail)) | ||
| } | ||
| if len(e.Actions) > 0 { | ||
| sb.WriteString("\n") | ||
| for i, action := range e.Actions { | ||
| sb.WriteString("\n") | ||
| if i > 0 { | ||
| sb.WriteString(colorErrorMuted.Render(ErrorActionPrefix + action.Label + " " + action.Value)) | ||
| } else { | ||
| sb.WriteString(colorErrorAction.Render(ErrorActionPrefix+action.Label+" ")) | ||
| sb.WriteString(lipgloss.NewStyle().Bold(true).Render(action.Value)) | ||
| } | ||
| } | ||
| } | ||
| return sb.String() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package output | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
|
|
||
| "golang.org/x/term" | ||
| ) | ||
|
|
||
| // ColorSink emits events like PlainSink but renders ErrorEvent with ANSI color | ||
| // when the output is a TTY and NO_COLOR is not set. | ||
| type ColorSink struct { | ||
| out io.Writer | ||
| colored bool | ||
| err error | ||
| } | ||
|
|
||
| // NewColorSink returns a ColorSink. Color is enabled only when out is a real | ||
| // terminal and the NO_COLOR environment variable is unset. | ||
| func NewColorSink(out io.Writer) *ColorSink { | ||
| if out == nil { | ||
| out = os.Stdout | ||
| } | ||
| return &ColorSink{out: out, colored: isColorTerminal(out)} | ||
| } | ||
|
|
||
| func (s *ColorSink) Err() error { | ||
| return s.err | ||
| } | ||
|
|
||
| func (s *ColorSink) setErr(err error) { | ||
| if s.err == nil && err != nil { | ||
| s.err = err | ||
| } | ||
| } | ||
|
|
||
| func (s *ColorSink) emit(event any) { | ||
| var ( | ||
| line string | ||
| ok bool | ||
| ) | ||
| if s.colored { | ||
| line, ok = FormatColorEventLine(event) | ||
| } else { | ||
| line, ok = FormatEventLine(event) | ||
| } | ||
| if !ok { | ||
| return | ||
| } | ||
| _, err := fmt.Fprintln(s.out, line) | ||
| s.setErr(err) | ||
| } | ||
|
|
||
| // isColorTerminal reports whether w is a TTY and NO_COLOR is unset. | ||
| func isColorTerminal(w io.Writer) bool { | ||
| if os.Getenv("NO_COLOR") != "" { | ||
| return false | ||
| } | ||
| f, ok := w.(*os.File) | ||
| if !ok { | ||
| return false | ||
| } | ||
| return term.IsTerminal(int(f.Fd())) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package output | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestColorSink_NoColor_FallsBackToPlain(t *testing.T) { | ||
| t.Setenv("NO_COLOR", "1") | ||
|
|
||
| var out bytes.Buffer | ||
| sink := NewColorSink(&out) | ||
| assert.False(t, sink.colored) | ||
|
|
||
| Emit(sink, ErrorEvent{ | ||
| Title: "Connection failed", | ||
| Summary: "Cannot connect to Docker", | ||
| Actions: []ErrorAction{{Label: "Start Docker:", Value: "open -a Docker"}}, | ||
| }) | ||
|
|
||
| expected := "Error: Connection failed\n Cannot connect to Docker\n ==> Start Docker: open -a Docker\n" | ||
| assert.Equal(t, expected, out.String()) | ||
| } | ||
|
|
||
| func TestColorSink_NonTTY_FallsBackToPlain(t *testing.T) { | ||
| // bytes.Buffer is not an *os.File, so isColorTerminal returns false. | ||
| var out bytes.Buffer | ||
| sink := NewColorSink(&out) | ||
| assert.False(t, sink.colored) | ||
|
|
||
| Emit(sink, ErrorEvent{Title: "Something broke"}) | ||
| assert.Equal(t, "Error: Something broke\n", out.String()) | ||
| } | ||
|
|
||
| func TestColorSink_ColoredMode_RendersErrorWithMarkers(t *testing.T) { | ||
| // Force colored mode directly to test rendering without a real TTY. | ||
| var out bytes.Buffer | ||
| sink := &ColorSink{out: &out, colored: true} | ||
|
|
||
| Emit(sink, ErrorEvent{ | ||
| Title: "Docker is not available", | ||
| Summary: "cannot connect to daemon", | ||
| Actions: []ErrorAction{ | ||
| {Label: "Start Docker:", Value: "open -a Docker"}, | ||
| {Label: "Install Docker:", Value: "https://docs.docker.com/get-docker/"}, | ||
| }, | ||
| }) | ||
|
|
||
| got := out.String() | ||
| assert.Contains(t, got, "Docker is not available") | ||
| assert.Contains(t, got, "cannot connect to daemon") | ||
| assert.Contains(t, got, "Start Docker:") | ||
| assert.Contains(t, got, "open -a Docker") | ||
| assert.Contains(t, got, "Install Docker:") | ||
| } | ||
|
|
||
| func TestColorSink_NonErrorEvents_DelegateToPlain(t *testing.T) { | ||
| var out bytes.Buffer | ||
| sink := &ColorSink{out: &out, colored: true} | ||
|
|
||
| EmitInfo(sink, "hello world") | ||
| assert.Equal(t, "hello world\n", out.String()) | ||
| } | ||
|
|
||
| func TestIsColorTerminal_NoColorEnv(t *testing.T) { | ||
| t.Setenv("NO_COLOR", "1") | ||
| var out bytes.Buffer | ||
| assert.False(t, isColorTerminal(&out)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package integration_test | ||
|
|
||
| import ( | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/localstack/lstk/test/integration/env" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // unhealthyDockerEnv returns an environment with DOCKER_HOST pointing to a | ||
| // non-existent Unix socket so that the Docker health check fails. | ||
| func unhealthyDockerEnv() env.Environ { | ||
| return env.With(env.Key("DOCKER_HOST"), "unix:///var/run/docker-does-not-exist.sock") | ||
| } | ||
|
|
||
| func TestStartShowsDockerErrorWhenUnhealthy(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("Unix socket test") | ||
| } | ||
|
|
||
| stdout, _, err := runLstk(t, testContext(t), "", unhealthyDockerEnv(), "start") | ||
| require.Error(t, err) | ||
| requireExitCode(t, 1, err) | ||
| assert.Contains(t, stdout, "Docker is not available") | ||
| assert.Contains(t, stdout, "Install Docker:") | ||
| } | ||
|
|
||
| func TestStopShowsDockerErrorWhenUnhealthy(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("Unix socket test") | ||
| } | ||
|
|
||
| stdout, _, err := runLstk(t, testContext(t), "", unhealthyDockerEnv(), "stop") | ||
| require.Error(t, err) | ||
| requireExitCode(t, 1, err) | ||
| assert.Contains(t, stdout, "Docker is not available") | ||
| assert.Contains(t, stdout, "Install Docker:") | ||
| } | ||
|
|
||
| func TestStatusShowsDockerErrorWhenUnhealthy(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("Unix socket test") | ||
| } | ||
|
|
||
| stdout, _, err := runLstk(t, testContext(t), "", unhealthyDockerEnv(), "status") | ||
| require.Error(t, err) | ||
| requireExitCode(t, 1, err) | ||
| assert.Contains(t, stdout, "Docker is not available") | ||
| assert.Contains(t, stdout, "Install Docker:") | ||
| } | ||
|
|
||
| func TestLogsShowsDockerErrorWhenUnhealthy(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("Unix socket test") | ||
| } | ||
|
|
||
| stdout, _, err := runLstk(t, testContext(t), "", unhealthyDockerEnv(), "logs") | ||
| require.Error(t, err) | ||
| requireExitCode(t, 1, err) | ||
| assert.Contains(t, stdout, "Docker is not available") | ||
| assert.Contains(t, stdout, "Install Docker:") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.