Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

refactor(cli): migrate tabs to cobra subcommands with proper flags

Bosch98d46099fe8b
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index 534642a0..1dae251d 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -305,7 +305,34 @@ func init() {
// clickCmd now uses proper cobra flags (see below)
// hoverCmd now uses proper cobra flags (see below)
// textCmd now uses proper cobra flags (see below)
- tabsCmd.DisableFlagParsing = true
+ // tabsCmd: proper cobra subcommands for new/close
+ // Other tab operations (navigate, snapshot, etc.) use top-level commands with --tab flag
+ tabsCmd.AddCommand(&cobra.Command{
+ Use: "new [url]",
+ Short: "Open a new tab",
+ Args: cobra.MaximumNArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ cfg := config.Load()
+ runCLIWith(cfg, func(client *http.Client, base, token string) {
+ body := map[string]any{"action": "new"}
+ if len(args) > 0 {
+ body["url"] = args[0]
+ }
+ browseractions.TabNew(client, base, token, body)
+ })
+ },
+ })
+ tabsCmd.AddCommand(&cobra.Command{
+ Use: "close <tabId>",
+ Short: "Close a tab",
+ Args: cobra.ExactArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+ cfg := config.Load()
+ runCLIWith(cfg, func(client *http.Client, base, token string) {
+ browseractions.TabClose(client, base, token, args[0])
+ })
+ },
+ })
uploadCmd.Flags().StringP("selector", "s", "", "CSS selector for file input")
downloadCmd.Flags().StringP("output", "o", "", "Save downloaded file to path")
diff --git a/internal/cli/actions/actions_tabs.go b/internal/cli/actions/actions_tabs.go
index 6351d140..80fd1b64 100644
--- a/internal/cli/actions/actions_tabs.go
+++ b/internal/cli/actions/actions_tabs.go
@@ -291,3 +291,23 @@ func TabOperation(client *http.Client, base, token string, op string, args []str
cli.Fatal("Unknown tab operation: %s", op)
}
}
+
+// TabNew opens a new tab (exported for cobra subcommand).
+func TabNew(client *http.Client, base, token string, body map[string]any) {
+ // Check if any instances are running
+ instances := getInstances(client, base, token)
+ if len(instances) == 0 {
+ fmt.Fprintln(os.Stderr, cli.StyleStderr(cli.WarningStyle, "No instances running, launching default..."))
+ launchInstance(client, base, token, "default")
+ fmt.Fprintln(os.Stderr, cli.StyleStderr(cli.SuccessStyle, "Instance launched"))
+ }
+ apiclient.DoPost(client, base, token, "/tab", body)
+}
+
+// TabClose closes a tab by ID (exported for cobra subcommand).
+func TabClose(client *http.Client, base, token string, tabID string) {
+ apiclient.DoPost(client, base, token, "/tab", map[string]any{
+ "action": "close",
+ "tabId": tabID,
+ })
+}