Skip to content

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

fix(cli): negative-positional rewrite consults persistent flags so --server/--agent-id before a subcommand keeps its value and the path (PIN-419)

Luigi Agostic8d81fd639f6
diff --git a/cmd/pinchtab/negative_positionals.go b/cmd/pinchtab/negative_positionals.go
index dc646d9c..67d7b559 100644
--- a/cmd/pinchtab/negative_positionals.go
+++ b/cmd/pinchtab/negative_positionals.go
@@ -112,7 +112,12 @@ func consumesNextToken(cmd *cobra.Command, arg string) bool {
if attached {
return false
}
- return takesValue(cmd.Flags().Lookup(name), cmd.InheritedFlags().Lookup(name))
+ // PersistentFlags too: a value-flag written BEFORE the subcommand (the remote
+ // form `pinchtab --server <url> set geo …`) is classified on the root, whose
+ // persistent flags (--server, --agent-id) are not yet merged into Flags() at
+ // this pre-Execute stage, so without this the URL reads as a positional and the
+ // subcommand path is lost.
+ return takesValue(cmd.Flags().Lookup(name), cmd.InheritedFlags().Lookup(name), cmd.PersistentFlags().Lookup(name))
}
// A shorthand bundle: pflag walks the characters and gives the REST of the token to
@@ -126,7 +131,7 @@ func consumesNextToken(cmd *cobra.Command, arg string) bool {
// non-ASCII byte is not a flag this walk can reason about.
return false
}
- if !takesValue(cmd.Flags().ShorthandLookup(c), cmd.InheritedFlags().ShorthandLookup(c)) {
+ if !takesValue(cmd.Flags().ShorthandLookup(c), cmd.InheritedFlags().ShorthandLookup(c), cmd.PersistentFlags().ShorthandLookup(c)) {
continue
}
return i == len(shorthands)-1
diff --git a/cmd/pinchtab/negative_positionals_test.go b/cmd/pinchtab/negative_positionals_test.go
index 7248b8b2..51bfbf46 100644
--- a/cmd/pinchtab/negative_positionals_test.go
+++ b/cmd/pinchtab/negative_positionals_test.go
@@ -51,6 +51,21 @@ func TestNegativeArgumentsAreMovedBehindTheFlags(t *testing.T) {
args: []string{"set", "geo", "-33.8", "151.2", "--json"},
want: []string{"set", "geo", "--json", "--", "-33.8", "151.2"},
},
+ {
+ // PIN-419: a value-taking PERSISTENT flag (--server) before the subcommand.
+ // It is classified on the root, whose persistent flags are not yet merged
+ // into Flags() at rewrite time, so on HEAD --server does not consume the URL:
+ // the URL becomes a positional, the set-geo path is lost, and cobra reports
+ // the URL as an "unknown command".
+ name: "a persistent --server before the subcommand keeps its value and the path",
+ args: []string{"--server", "http://127.0.0.1:19227", "set", "geo", "51.5", "-0.12"},
+ want: []string{"set", "geo", "--server", "http://127.0.0.1:19227", "--", "51.5", "-0.12"},
+ },
+ {
+ name: "a persistent --agent-id before the subcommand keeps its value and the path",
+ args: []string{"--agent-id", "agent-7", "mouse", "move", "-5", "-5"},
+ want: []string{"mouse", "move", "--agent-id", "agent-7", "--", "-5", "-5"},
+ },
} {
t.Run(tc.name, func(t *testing.T) {
got := rewriteNegativeNumberArgs(rootCmd, tc.args)