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
|
||||
|
||||
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)
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ func NewStatusCommand() *cobra.Command {
|
|||
Aliases: []string{"s"},
|
||||
Short: "Show picoclaw status",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
statusCmd()
|
||||
StatusCmd()
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue