Skip to content

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

refactor(cli): migrate find command to proper cobra flags

Bosch86abe13aead5
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index 6b45e47f..641fce46 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -239,10 +239,11 @@ var instanceCmd = &cobra.Command{
var findCmd = &cobra.Command{
Use: "find <query>",
Short: "Find elements by natural language query",
+ Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
cfg := config.Load()
runCLIWith(cfg, func(client *http.Client, base, token string) {
- browseractions.Find(client, base, token, args)
+ browseractions.FindWithFlags(client, base, token, args[0], cmd)
})
},
}
@@ -288,7 +289,7 @@ func init() {
snapCmd.DisableFlagParsing = true
screenshotCmd.DisableFlagParsing = true
// pdfCmd now uses proper cobra flags (see below)
- findCmd.DisableFlagParsing = true
+ // findCmd now uses proper cobra flags (see below)
navCmd.DisableFlagParsing = true
clickCmd.DisableFlagParsing = true
hoverCmd.DisableFlagParsing = true
@@ -318,6 +319,11 @@ func init() {
pdfCmd.Flags().Bool("file-output", false, "Use server-side file output")
pdfCmd.Flags().String("path", "", "Server-side output path")
+ findCmd.Flags().String("tab", "", "Tab ID")
+ findCmd.Flags().String("threshold", "", "Minimum similarity score (0-1)")
+ findCmd.Flags().Bool("explain", false, "Show score breakdown")
+ findCmd.Flags().Bool("ref-only", false, "Output just the element ref")
+
rootCmd.AddCommand(quickCmd)
rootCmd.AddCommand(navCmd)
rootCmd.AddCommand(snapCmd)
diff --git a/internal/cli/actions/actions_find.go b/internal/cli/actions/actions_find.go
index abb5cb98..629081af 100644
--- a/internal/cli/actions/actions_find.go
+++ b/internal/cli/actions/actions_find.go
@@ -6,6 +6,7 @@ import (
"github.com/pinchtab/pinchtab/internal/cli"
"github.com/pinchtab/pinchtab/internal/cli/apiclient"
+ "github.com/spf13/cobra"
)
func Find(client *http.Client, base, token string, args []string) {
@@ -65,3 +66,33 @@ func Find(client *http.Client, base, token string, args []string) {
cli.Fatal("No element found")
}
}
+
+func FindWithFlags(client *http.Client, base, token string, query string, cmd *cobra.Command) {
+ tabID, _ := cmd.Flags().GetString("tab")
+ threshold, _ := cmd.Flags().GetString("threshold")
+ explain, _ := cmd.Flags().GetBool("explain")
+ refOnly, _ := cmd.Flags().GetBool("ref-only")
+
+ body := map[string]any{"query": query}
+ if threshold != "" {
+ body["threshold"] = threshold
+ }
+ if explain {
+ body["explain"] = true
+ }
+
+ path := "/find"
+ if tabID != "" {
+ path = fmt.Sprintf("/tabs/%s/find", tabID)
+ }
+
+ result := apiclient.DoPost(client, base, token, path, body)
+
+ if refOnly {
+ if ref, ok := result["best_ref"].(string); ok && ref != "" {
+ fmt.Println(ref)
+ return
+ }
+ cli.Fatal("No element found")
+ }
+}