@@ -85,33 +85,41 @@ export function consumeGatewayFastPathRootOptionToken(
|
85 | 85 | return 0; |
86 | 86 | } |
87 | 87 | |
88 | | -/** Resolve the gateway command path from raw argv for catalog/policy lookups. */ |
89 | | -export function resolveGatewayCatalogCommandPath(argv: string[]): string[] | null { |
| 88 | +function resolveGatewayCommandStart(argv: string[]): { |
| 89 | +args: string[]; |
| 90 | +startIndex: number; |
| 91 | +} | null { |
90 | 92 | const args = argv.slice(2); |
91 | | -let sawGateway = false; |
92 | | - |
93 | 93 | for (let index = 0; index < args.length; index += 1) { |
94 | 94 | const arg = args[index]; |
95 | 95 | if (!arg || arg === "--") { |
96 | | -break; |
| 96 | +return null; |
97 | 97 | } |
98 | | -if (!sawGateway) { |
99 | | -const consumed = consumeRootOptionToken(args, index); |
100 | | -if (consumed > 0) { |
101 | | -index += consumed - 1; |
102 | | -continue; |
103 | | -} |
104 | | -if (arg.startsWith("-")) { |
105 | | -continue; |
106 | | -} |
107 | | -if (arg !== "gateway") { |
108 | | -return null; |
109 | | -} |
110 | | -sawGateway = true; |
| 98 | +const consumed = consumeRootOptionToken(args, index); |
| 99 | +if (consumed > 0) { |
| 100 | +index += consumed - 1; |
111 | 101 | continue; |
112 | 102 | } |
| 103 | +if (arg.startsWith("-")) { |
| 104 | +continue; |
| 105 | +} |
| 106 | +return arg === "gateway" ? { args, startIndex: index + 1 } : null; |
| 107 | +} |
| 108 | +return null; |
| 109 | +} |
113 | 110 | |
114 | | -const consumed = consumeGatewayRunOptionToken(args, index); |
| 111 | +/** Resolve the gateway command path from raw argv for catalog/policy lookups. */ |
| 112 | +export function resolveGatewayCatalogCommandPath(argv: string[]): string[] | null { |
| 113 | +const gateway = resolveGatewayCommandStart(argv); |
| 114 | +if (!gateway) { |
| 115 | +return null; |
| 116 | +} |
| 117 | +for (let index = gateway.startIndex; index < gateway.args.length; index += 1) { |
| 118 | +const arg = gateway.args[index]; |
| 119 | +if (!arg || arg === "--") { |
| 120 | +break; |
| 121 | +} |
| 122 | +const consumed = consumeGatewayRunOptionToken(gateway.args, index); |
115 | 123 | if (consumed > 0) { |
116 | 124 | index += consumed - 1; |
117 | 125 | continue; |
@@ -122,44 +130,31 @@ export function resolveGatewayCatalogCommandPath(argv: string[]): string[] | nul
|
122 | 130 | return ["gateway", arg]; |
123 | 131 | } |
124 | 132 | |
125 | | -return sawGateway ? ["gateway"] : null; |
| 133 | +return ["gateway"]; |
126 | 134 | } |
127 | 135 | |
128 | 136 | /** Resolve destructive gateway-run flags before Commander registration. */ |
129 | 137 | export function resolveGatewayRunPreBootstrapOptions( |
130 | 138 | argv: string[], |
131 | 139 | ): { force: boolean; reset: boolean } | null { |
132 | | -const args = argv.slice(2); |
| 140 | +const gateway = resolveGatewayCommandStart(argv); |
| 141 | +if (!gateway) { |
| 142 | +return null; |
| 143 | +} |
133 | 144 | let force = false; |
134 | 145 | let reset = false; |
135 | | -let sawGateway = false; |
136 | 146 | let sawRun = false; |
137 | 147 | |
138 | | -for (let index = 0; index < args.length; index += 1) { |
139 | | -const arg = args[index]; |
| 148 | +for (let index = gateway.startIndex; index < gateway.args.length; index += 1) { |
| 149 | +const arg = gateway.args[index]; |
140 | 150 | if (!arg || arg === "--") { |
141 | 151 | break; |
142 | 152 | } |
143 | | -if (!sawGateway) { |
144 | | -const consumed = consumeRootOptionToken(args, index); |
145 | | -if (consumed > 0) { |
146 | | -index += consumed - 1; |
147 | | -continue; |
148 | | -} |
149 | | -if (arg.startsWith("-")) { |
150 | | -continue; |
151 | | -} |
152 | | -if (arg !== "gateway") { |
153 | | -return null; |
154 | | -} |
155 | | -sawGateway = true; |
156 | | -continue; |
157 | | -} |
158 | 153 | if (!sawRun && arg === "run") { |
159 | 154 | sawRun = true; |
160 | 155 | continue; |
161 | 156 | } |
162 | | -const consumed = consumeGatewayRunPreBootstrapOptionToken(args, index); |
| 157 | +const consumed = consumeGatewayRunPreBootstrapOptionToken(gateway.args, index); |
163 | 158 | if (consumed > 0) { |
164 | 159 | if (arg === "--force") { |
165 | 160 | force = true; |
@@ -179,5 +174,5 @@ export function resolveGatewayRunPreBootstrapOptions(
|
179 | 174 | } |
180 | 175 | } |
181 | 176 | |
182 | | -return sawGateway ? { force, reset } : null; |
| 177 | +return { force, reset }; |
183 | 178 | } |