Skip to content

Commit 9f6f271

Browse files
authored
feat(start): automatically run the status command if already started (#2980)
* feat(start): automatically run the status command if already started Rather than asking the user to run the command to get the values Run the command for him so start command always return the infos of the running stack. * fix: test * fix: test
1 parent d3acc10 commit 9f6f271

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

internal/start/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignore
4242
}
4343
if err := utils.AssertSupabaseDbIsRunning(); err == nil {
4444
fmt.Fprintln(os.Stderr, utils.Aqua("supabase start")+" is already running.")
45-
utils.CmdSuggestion = fmt.Sprintf("Run %s to show status of local Supabase containers.", utils.Aqua("supabase status"))
46-
return nil
45+
names := status.CustomName{}
46+
return status.Run(ctx, names, utils.OutputPretty, fsys)
4747
} else if !errors.Is(err, utils.ErrNotRunning) {
4848
return err
4949
}

internal/start/start_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ func TestStartCommand(t *testing.T) {
5757
assert.Empty(t, apitest.ListUnmatchedRequests())
5858
})
5959

60-
t.Run("noop if database is already running", func(t *testing.T) {
60+
t.Run("show status if database is already running", func(t *testing.T) {
61+
var running []types.Container
62+
for _, name := range utils.GetDockerIds() {
63+
running = append(running, types.Container{
64+
Names: []string{name + "_test"},
65+
})
66+
}
6167
// Setup in-memory fs
6268
fsys := afero.NewMemMapFs()
6369
require.NoError(t, utils.WriteConfig(fsys, false))
@@ -68,6 +74,17 @@ func TestStartCommand(t *testing.T) {
6874
Get("/v" + utils.Docker.ClientVersion() + "/containers").
6975
Reply(http.StatusOK).
7076
JSON(types.ContainerJSON{})
77+
78+
gock.New(utils.Docker.DaemonHost()).
79+
Get("/v" + utils.Docker.ClientVersion() + "/containers/supabase_db_start/json").
80+
Reply(http.StatusOK).
81+
JSON(types.ContainerJSON{ContainerJSONBase: &types.ContainerJSONBase{
82+
State: &types.ContainerState{Running: true},
83+
}})
84+
gock.New(utils.Docker.DaemonHost()).
85+
Get("/v" + utils.Docker.ClientVersion() + "/containers/json").
86+
Reply(http.StatusOK).
87+
JSON(running)
7188
// Run test
7289
err := Run(context.Background(), fsys, []string{}, false)
7390
// Check error

0 commit comments

Comments
 (0)