Skip to content

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

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

Boschbd6a3fc5160e
diff --git a/cmd/pinchtab/cmd_cli.go b/cmd/pinchtab/cmd_cli.go
index 641fce46..439879dd 100644
--- a/cmd/pinchtab/cmd_cli.go
+++ b/cmd/pinchtab/cmd_cli.go
@@ -75,7 +75,7 @@ var screenshotCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cfg := config.Load()
runCLIWith(cfg, func(client *http.Client, base, token string) {
- browseractions.Screenshot(client, base, token, args)
+ browseractions.ScreenshotWithFlags(client, base, token, cmd)
})
},
}
@@ -189,7 +189,7 @@ var textCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
cfg := config.Load()
runCLIWith(cfg, func(client *http.Client, base, token string) {
- browseractions.Text(client, base, token, args)
+ browseractions.TextWithFlags(client, base, token, cmd)
})
},
}
@@ -287,18 +287,22 @@ func init() {
// FParseErrWhitelist silently swallows unknown flags (dropping them from args),
// so we must disable cobra's parser entirely and let the action code handle flags.
snapCmd.DisableFlagParsing = true
- screenshotCmd.DisableFlagParsing = true
+ // screenshotCmd now uses proper cobra flags (see below)
// pdfCmd now uses proper cobra flags (see below)
// findCmd now uses proper cobra flags (see below)
navCmd.DisableFlagParsing = true
clickCmd.DisableFlagParsing = true
hoverCmd.DisableFlagParsing = true
- textCmd.DisableFlagParsing = true
+ // 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")
+ screenshotCmd.Flags().StringP("output", "o", "", "Save screenshot to file path")
+ screenshotCmd.Flags().StringP("quality", "q", "", "JPEG quality (0-100)")
+ screenshotCmd.Flags().String("tab", "", "Tab ID")
+
pdfCmd.Flags().StringP("output", "o", "", "Save PDF to file path")
pdfCmd.Flags().String("tab", "", "Tab ID")
pdfCmd.Flags().Bool("landscape", false, "Landscape orientation")
@@ -324,6 +328,9 @@ func init() {
findCmd.Flags().Bool("explain", false, "Show score breakdown")
findCmd.Flags().Bool("ref-only", false, "Output just the element ref")
+ textCmd.Flags().Bool("raw", false, "Raw extraction mode")
+ textCmd.Flags().String("tab", "", "Tab ID")
+
rootCmd.AddCommand(quickCmd)
rootCmd.AddCommand(navCmd)
rootCmd.AddCommand(snapCmd)
diff --git a/internal/cli/actions/actions_screenshot.go b/internal/cli/actions/actions_screenshot.go
index e50145c2..d90a2ba9 100644
--- a/internal/cli/actions/actions_screenshot.go
+++ b/internal/cli/actions/actions_screenshot.go
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/pinchtab/pinchtab/internal/cli"
"github.com/pinchtab/pinchtab/internal/cli/apiclient"
+ "github.com/spf13/cobra"
"net/http"
"net/url"
"os"
@@ -47,3 +48,29 @@ func Screenshot(client *http.Client, base, token string, args []string) {
}
fmt.Println(cli.StyleStdout(cli.SuccessStyle, fmt.Sprintf("Saved %s (%d bytes)", outFile, len(data))))
}
+
+func ScreenshotWithFlags(client *http.Client, base, token string, cmd *cobra.Command) {
+ params := url.Values{}
+ params.Set("raw", "true")
+
+ outFile, _ := cmd.Flags().GetString("output")
+ if v, _ := cmd.Flags().GetString("quality"); v != "" {
+ params.Set("quality", v)
+ }
+ if v, _ := cmd.Flags().GetString("tab"); v != "" {
+ params.Set("tabId", v)
+ }
+
+ if outFile == "" {
+ outFile = fmt.Sprintf("screenshot-%s.jpg", time.Now().Format("20060102-150405"))
+ }
+
+ data := apiclient.DoGetRaw(client, base, token, "/screenshot", params)
+ if data == nil {
+ return
+ }
+ if err := os.WriteFile(outFile, data, 0600); err != nil {
+ cli.Fatal("Write failed: %v", err)
+ }
+ fmt.Println(cli.StyleStdout(cli.SuccessStyle, fmt.Sprintf("Saved %s (%d bytes)", outFile, len(data))))
+}
diff --git a/internal/cli/actions/actions_text.go b/internal/cli/actions/actions_text.go
index c3a06fa5..035f1885 100644
--- a/internal/cli/actions/actions_text.go
+++ b/internal/cli/actions/actions_text.go
@@ -2,6 +2,7 @@ package actions
import (
"github.com/pinchtab/pinchtab/internal/cli/apiclient"
+ "github.com/spf13/cobra"
"net/http"
"net/url"
)
@@ -21,3 +22,14 @@ func Text(client *http.Client, base, token string, args []string) {
}
apiclient.DoGet(client, base, token, "/text", params)
}
+
+func TextWithFlags(client *http.Client, base, token string, cmd *cobra.Command) {
+ params := url.Values{}
+ if v, _ := cmd.Flags().GetBool("raw"); v {
+ params.Set("mode", "raw")
+ }
+ if v, _ := cmd.Flags().GetString("tab"); v != "" {
+ params.Set("tabId", v)
+ }
+ apiclient.DoGet(client, base, token, "/text", params)
+}