@@ -181,3 +181,75 @@ func TestParse_FlagCombinations(t *testing.T) {
181181 t .Errorf ("unexpected config: %+v" , cfg )
182182 }
183183}
184+
185+ // Bug 1: --search-dirs greedily consumes single-dash flags and commands
186+
187+ func TestParse_SearchDirsStopsAtCommand_Install (t * testing.T ) {
188+ cfg , err := Parse ([]string {"--search-dirs" , "/tmp" , "install" })
189+ if err != nil {
190+ t .Fatal (err )
191+ }
192+ if cfg .Command != "install" {
193+ t .Errorf ("expected command=install, got %q (search-dirs consumed it: %v)" , cfg .Command , cfg .SearchDirs )
194+ }
195+ if len (cfg .SearchDirs ) != 1 || cfg .SearchDirs [0 ] != "/tmp" {
196+ t .Errorf ("expected SearchDirs=[/tmp], got %v" , cfg .SearchDirs )
197+ }
198+ }
199+
200+ func TestParse_SearchDirsRejectsSingleDashFlag (t * testing.T ) {
201+ // --search-dirs -v should error, not silently consume -v as a directory
202+ _ , err := Parse ([]string {"--search-dirs" , "-v" })
203+ if err == nil {
204+ t .Error ("expected error when --search-dirs is followed by a flag" )
205+ }
206+ }
207+
208+ func TestParse_SearchDirsStopsAtCommand_Uninstall (t * testing.T ) {
209+ cfg , err := Parse ([]string {"--search-dirs" , "/opt" , "uninstall" })
210+ if err != nil {
211+ t .Fatal (err )
212+ }
213+ if cfg .Command != "uninstall" {
214+ t .Errorf ("expected command=uninstall, got %q (search-dirs consumed it: %v)" , cfg .Command , cfg .SearchDirs )
215+ }
216+ if len (cfg .SearchDirs ) != 1 || cfg .SearchDirs [0 ] != "/opt" {
217+ t .Errorf ("expected SearchDirs=[/opt], got %v" , cfg .SearchDirs )
218+ }
219+ }
220+
221+ func TestParse_SearchDirsStopsAtCommand_SendTelemetry (t * testing.T ) {
222+ cfg , err := Parse ([]string {"--search-dirs" , "/data" , "send-telemetry" })
223+ if err != nil {
224+ t .Fatal (err )
225+ }
226+ if cfg .Command != "send-telemetry" {
227+ t .Errorf ("expected command=send-telemetry, got %q (search-dirs consumed it: %v)" , cfg .Command , cfg .SearchDirs )
228+ }
229+ }
230+
231+ func TestParse_SearchDirsStopsAtCommand_Configure (t * testing.T ) {
232+ cfg , err := Parse ([]string {"--search-dirs" , "/data" , "configure" })
233+ if err != nil {
234+ t .Fatal (err )
235+ }
236+ if cfg .Command != "configure" {
237+ t .Errorf ("expected command=configure, got %q (search-dirs consumed it: %v)" , cfg .Command , cfg .SearchDirs )
238+ }
239+ }
240+
241+ // Bug 2: --html accepts flags as its filename argument
242+
243+ func TestParse_HTMLRejectsFlag (t * testing.T ) {
244+ _ , err := Parse ([]string {"--html" , "--verbose" })
245+ if err == nil {
246+ t .Error ("expected error when --html argument looks like a flag, got nil" )
247+ }
248+ }
249+
250+ func TestParse_HTMLRejectsDashFlag (t * testing.T ) {
251+ _ , err := Parse ([]string {"--html" , "-v" })
252+ if err == nil {
253+ t .Error ("expected error when --html argument is -v, got nil" )
254+ }
255+ }
0 commit comments