Skip to content

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

refactor(cli): migrate click and hover to proper cobra flags

Bosch7ee570e1fcb8
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index 58a0c5bf..534642a0 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -50,10 +50,15 @@ var snapCmd = &cobra.Command{
var clickCmd = &cobra.Command{
Use: "click <ref>",
Short: "Click element",
+ Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
+ ref := ""
+ if len(args) > 0 {
+ ref = args[0]
+ }
cfg := config.Load()
runCLIWith(cfg, func(client *http.Client, base, token string) {
- browseractions.Action(client, base, token, "click", args)
+ browseractions.ActionWithFlags(client, base, token, "click", ref, cmd)
})
},
}
@@ -141,10 +146,15 @@ var fillCmd = &cobra.Command{
var hoverCmd = &cobra.Command{
Use: "hover <ref>",
Short: "Hover element",
+ Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
+ ref := ""
+ if len(args) > 0 {
+ ref = args[0]
+ }
cfg := config.Load()
runCLIWith(cfg, func(client *http.Client, base, token string) {
- browseractions.Action(client, base, token, "hover", args)
+ browseractions.ActionWithFlags(client, base, token, "hover", ref, cmd)
})
},
}
@@ -292,14 +302,18 @@ func init() {
// pdfCmd now uses proper cobra flags (see below)
// findCmd now uses proper cobra flags (see below)
// navCmd now uses proper cobra flags (see below)
- clickCmd.DisableFlagParsing = true
- hoverCmd.DisableFlagParsing = true
+ // 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
uploadCmd.Flags().StringP("selector", "s", "", "CSS selector for file input")
downloadCmd.Flags().StringP("output", "o", "", "Save downloaded file to path")
+ clickCmd.Flags().String("css", "", "CSS selector instead of ref")
+ clickCmd.Flags().Bool("wait-nav", false, "Wait for navigation after click")
+ hoverCmd.Flags().String("css", "", "CSS selector instead of ref")
+
snapCmd.Flags().BoolP("interactive", "i", false, "Filter interactive elements only")
snapCmd.Flags().BoolP("compact", "c", false, "Compact output format")
snapCmd.Flags().Bool("text", false, "Text output format")
diff --git a/internal/cli/actions/actions_element.go b/internal/cli/actions/actions_element.go
index f692e717..66e8fb23 100644
--- a/internal/cli/actions/actions_element.go
+++ b/internal/cli/actions/actions_element.go
@@ -3,11 +3,33 @@ package actions
import (
"github.com/pinchtab/pinchtab/internal/cli"
"github.com/pinchtab/pinchtab/internal/cli/apiclient"
+ "github.com/spf13/cobra"
"net/http"
"strconv"
"strings"
)
+func ActionWithFlags(client *http.Client, base, token, kind, refArg string, cmd *cobra.Command) {
+ body := map[string]any{"kind": kind}
+
+ css, _ := cmd.Flags().GetString("css")
+ if css != "" {
+ body["selector"] = css
+ } else if refArg != "" {
+ body["ref"] = refArg
+ } else {
+ cli.Fatal("Usage: pinchtab %s <ref> or pinchtab %s --css <selector>", kind, kind)
+ }
+
+ if kind == "click" {
+ if v, _ := cmd.Flags().GetBool("wait-nav"); v {
+ body["waitNav"] = true
+ }
+ }
+
+ apiclient.DoPost(client, base, token, "/action", body)
+}
+
func Action(client *http.Client, base, token, kind string, args []string) {
body := map[string]any{"kind": kind}