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
This commit is contained in:
parent
9c9524f934
commit
04f6f90071
4 changed files with 13 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package gateway
|
package gateway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/sipeed/picoclaw/cmd/picoclaw/internal/status"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -11,8 +12,14 @@ func NewGatewayCommand() *cobra.Command {
|
||||||
Use: "gateway",
|
Use: "gateway",
|
||||||
Aliases: []string{"g"},
|
Aliases: []string{"g"},
|
||||||
Short: "Start picoclaw gateway",
|
Short: "Start picoclaw gateway",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(_ *cobra.Command, _ []string) error {
|
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)
|
return gatewayCmd(debug)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ func TestNewGatewayCommand(t *testing.T) {
|
||||||
assert.Nil(t, cmd.PersistentPreRun)
|
assert.Nil(t, cmd.PersistentPreRun)
|
||||||
assert.Nil(t, cmd.PersistentPostRun)
|
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.True(t, cmd.HasFlags())
|
||||||
assert.NotNil(t, cmd.Flags().Lookup("debug"))
|
assert.NotNil(t, cmd.Flags().Lookup("debug"))
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ func NewStatusCommand() *cobra.Command {
|
||||||
Aliases: []string{"s"},
|
Aliases: []string{"s"},
|
||||||
Short: "Show picoclaw status",
|
Short: "Show picoclaw status",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
statusCmd()
|
StatusCmd()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/sipeed/picoclaw/pkg/auth"
|
"github.com/sipeed/picoclaw/pkg/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
func statusCmd() {
|
func StatusCmd() {
|
||||||
cfg, err := internal.LoadConfig()
|
cfg, err := internal.LoadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error loading config: %v\n", err)
|
fmt.Printf("Error loading config: %v\n", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue