From 04f6f90071996997f32b246c001c649f73096e1f Mon Sep 17 00:00:00 2001 From: GhostC <1276537536@qq.com> Date: Sat, 28 Feb 2026 22:33:31 +0800 Subject: [PATCH] fix: prevent gateway status from starting full gateway runtime - Fix issue where 'picoclaw gateway status' would start a full gateway worker - Add argument check in gateway command to delegate 'status' to status command - Export StatusCmd() function to allow gateway package to call it - Update gateway command to accept up to 1 argument for status subcommand Fixes #671 --- cmd/picoclaw/internal/gateway/command.go | 11 +++++++++-- cmd/picoclaw/internal/gateway/command_test.go | 3 ++- cmd/picoclaw/internal/status/command.go | 2 +- cmd/picoclaw/internal/status/helpers.go | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/picoclaw/internal/gateway/command.go b/cmd/picoclaw/internal/gateway/command.go index 66a56f9ce..a3ffafcfc 100644 --- a/cmd/picoclaw/internal/gateway/command.go +++ b/cmd/picoclaw/internal/gateway/command.go @@ -1,6 +1,7 @@ package gateway import ( + "github.com/sipeed/picoclaw/cmd/picoclaw/internal/status" "github.com/spf13/cobra" ) @@ -11,8 +12,14 @@ func NewGatewayCommand() *cobra.Command { Use: "gateway", Aliases: []string{"g"}, Short: "Start picoclaw gateway", - Args: cobra.NoArgs, - RunE: func(_ *cobra.Command, _ []string) error { + Args: cobra.MaximumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + // If "status" is provided as an argument, delegate to status command + if len(args) > 0 && args[0] == "status" { + status.StatusCmd() + return nil + } + // Otherwise, start the gateway return gatewayCmd(debug) }, } diff --git a/cmd/picoclaw/internal/gateway/command_test.go b/cmd/picoclaw/internal/gateway/command_test.go index 4d591ea67..411bb4d64 100644 --- a/cmd/picoclaw/internal/gateway/command_test.go +++ b/cmd/picoclaw/internal/gateway/command_test.go @@ -24,7 +24,8 @@ func TestNewGatewayCommand(t *testing.T) { assert.Nil(t, cmd.PersistentPreRun) assert.Nil(t, cmd.PersistentPostRun) - assert.False(t, cmd.HasSubCommands()) + // Gateway command now accepts up to 1 argument (for "status" subcommand) + assert.NotNil(t, cmd.Args) assert.True(t, cmd.HasFlags()) assert.NotNil(t, cmd.Flags().Lookup("debug")) diff --git a/cmd/picoclaw/internal/status/command.go b/cmd/picoclaw/internal/status/command.go index 9303ae2ec..8302aeb17 100644 --- a/cmd/picoclaw/internal/status/command.go +++ b/cmd/picoclaw/internal/status/command.go @@ -10,7 +10,7 @@ func NewStatusCommand() *cobra.Command { Aliases: []string{"s"}, Short: "Show picoclaw status", Run: func(cmd *cobra.Command, args []string) { - statusCmd() + StatusCmd() }, } diff --git a/cmd/picoclaw/internal/status/helpers.go b/cmd/picoclaw/internal/status/helpers.go index ab28f4885..2ad3ae5e9 100644 --- a/cmd/picoclaw/internal/status/helpers.go +++ b/cmd/picoclaw/internal/status/helpers.go @@ -8,7 +8,7 @@ import ( "github.com/sipeed/picoclaw/pkg/auth" ) -func statusCmd() { +func StatusCmd() { cfg, err := internal.LoadConfig() if err != nil { fmt.Printf("Error loading config: %v\n", err)