Repository: cli/cli
File: pkg/cmd/search/code/code.go (Go)

Code before:
	// Query qualifier flags
	cmd.Flags().StringVar(&opts.Query.Qualifiers.Extension, "extension", "", "Filter on file extension")
	cmd.Flags().StringVar(&opts.Query.Qualifiers.Filename, "filename", "", "Filter on filename")
	cmdutil.StringSliceEnumFlag(cmd, &opts.Query.Qualifiers.In, "match", "", nil, []string{"file", "path"}, "Restrict search to file contents or file path")
	cmd.Flags().StringVarP(&opts.Query.Qualifiers.Language, "language", "", "", "Filter results by language")
	cmd.Flags().StringSliceVarP(&opts.Query.Qualifiers.Repo, "repo", "R", nil, "Filter on repository")
	cmd.Flags().StringVar(&opts.Query.Qualifiers.Size, "size", "", "Filter on size range, in kilobytes")
	cmd.Flags().StringSliceVar(&opts.Query.Qualifiers.User, "owner", nil, "Filter on owner")

	return cmd
}

func codeRun(opts *CodeOptions) error {
	io := opts.IO
	if opts.WebMode {
		// Convert legacy `filename` and `extension` elasticsearch qualifiers to Blackbird's `path`
		// qualifier when opening web search.
		if opts.Query.Qualifiers.Filename != "" || opts.Query.Qualifiers.Extension != "" {
			cfg, err := opts.Config()
			if err != nil {
				return err
			}
			host, _ := cfg.Authentication().DefaultHost()
			// FIXME: Remove this check once GHES supports Blackbird.
			if host == ghinstance.Default() {
				filename, extension, _ := strings.Cut(opts.Query.Qualifiers.Filename, ".")
				if filename == "" {
					filename = "*"
				}
				// Prioritize file extension that may have been provided with the `--filename` flag.
				if extension == "" {
					if opts.Query.Qualifiers.Extension != "" {
						extension, _ = strings.CutPrefix(opts.Query.Qualifiers.Extension, ".")
					} else {
						extension = "*"
					}
				}
				opts.Query.Qualifiers.Filename = ""
				opts.Query.Qualifiers.Extension = ""
				opts.Query.Qualifiers.Path = fmt.Sprintf("%s.%s", filename, extension)
			}
		}
		url := opts.Searcher.URL(opts.Query)
		if io.IsStdoutTTY() {
			fmt.Fprintf(io.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(url))
		}
		return opts.Browser.Browse(url)
	}
	io.StartProgressIndicator()
	results, err := opts.Searcher.Code(opts.Query)
	io.StopProgressIndicator()

Review comment (suggestion):
**thought:** I suspect `strings.Cut` handles situations like `cli.tar.gz` better than [`filepath.Ext()`](https://pkg.go.dev/path/filepath#Ext), which would only return `.gz`. 🤔 

Code after:
	// Query qualifier flags
	cmd.Flags().StringVar(&opts.Query.Qualifiers.Extension, "extension", "", "Filter on file extension")
	cmd.Flags().StringVar(&opts.Query.Qualifiers.Filename, "filename", "", "Filter on filename")
	cmdutil.StringSliceEnumFlag(cmd, &opts.Query.Qualifiers.In, "match", "", nil, []string{"file", "path"}, "Restrict search to file contents or file path")
	cmd.Flags().StringVarP(&opts.Query.Qualifiers.Language, "language", "", "", "Filter results by language")
	cmd.Flags().StringSliceVarP(&opts.Query.Qualifiers.Repo, "repo", "R", nil, "Filter on repository")
	cmd.Flags().StringVar(&opts.Query.Qualifiers.Size, "size", "", "Filter on size range, in kilobytes")
	cmd.Flags().StringSliceVar(&opts.Query.Qualifiers.User, "owner", nil, "Filter on owner")

	return cmd
}

func codeRun(opts *CodeOptions) error {
	io := opts.IO
	if opts.WebMode {
		// Convert `filename` and `extension` legacy search qualifiers to the new code search's `path`
		// qualifier when used with `--web` because they are incompatible.
		if opts.Query.Qualifiers.Filename != "" || opts.Query.Qualifiers.Extension != "" {
			cfg, err := opts.Config()
			if err != nil {
				return err
			}
			host, _ := cfg.Authentication().DefaultHost()
			// FIXME: Remove this check once GHES supports the new `path` search qualifier.
			if !ghauth.IsEnterprise(host) {
				filename := opts.Query.Qualifiers.Filename
				extension := opts.Query.Qualifiers.Extension
				if extension != "" && !strings.HasPrefix(extension, ".") {
					extension = "." + extension
				}
				opts.Query.Qualifiers.Filename = ""
				opts.Query.Qualifiers.Extension = ""
				opts.Query.Qualifiers.Path = fmt.Sprintf("%s%s", filename, extension)
			}
		}
		url := opts.Searcher.URL(opts.Query)
		if io.IsStdoutTTY() {
			fmt.Fprintf(io.ErrOut, "Opening %s in your browser.\n", text.DisplayURL(url))
		}
		return opts.Browser.Browse(url)
	}
	io.StartProgressIndicator()
	results, err := opts.Searcher.Code(opts.Query)
	io.StopProgressIndicator()
	if err != nil {
		return err
	}
	if len(results.Items) == 0 && opts.Exporter == nil {
		return cmdutil.NewNoResultsError("no code results matched your search")
	}
	if err := io.StartPager(); err == nil {