Skip to content

fix: pass search arguments that start with a dash to the plugin - #813

Merged
linghengqian merged 8 commits into
version-fox:mainfrom
mateuscmtropical:fix/search-plugin-args
Nov 27, 2026
Merged

linghengqian merged 8 commits into
version-fox:mainfrom
mateuscmtropical:fix/search-plugin-args

Conversation

@mateuscmtropical

@mateuscmtropical mateuscmtropical commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #808

vfox search now reads its own options and hands every other argument after the SDK name to the plugin's Available hook, including the ones that start with a dash. So vfox search clang --no-cache reaches the plugin.

The rules (searchArgs in cmd/commands/search.go):

  • Before a --, vfox reads -h, -help and -debug wherever they are, each with one or two dashes and an optional =value, as the flag parser did on main. Only arguments that start with a dash count, so a plain debug goes to the plugin or names the SDK. An invalid value is an error, as on main.
  • The first other argument is the SDK name. The rest go to the plugin in their order. An empty SDK name stays empty, so vfox search "" echo fails with "sdk name is required" as on main.
  • -v, -V and --version are not vfox options in search. After the SDK name they go to the plugin like any other argument, and search --help does not list them. vfox --version still prints the version.
  • An SDK name that starts with a dash is a usage error before any lookup, before or after a --. The message points to vfox --version.
  • After a --, every argument goes to the plugin, help and debug flags included, except the SDK name when it comes after the --. So vfox search clang -- --help asks the plugin, and vfox search -- clang --no-cache and vfox search clang -- --no-cache keep working.

Cache: a search with plugin arguments skips the Available cache, so the plugin runs every time (option b from the review). The cost is one hook call, and usually a network request, for each search that passes arguments. A search without arguments is cached as before. A plugin that refreshes on a flag such as --no-cache should also delete .available.cache in its directory, so the next plain search is fresh. vfox-clang removes available.cache without the dot today, so its plain search stays cached until that is fixed in the plugin.

Docs: the search section in docs/usage/core-commands.md and docs/zh-hans/usage/core-commands.md describes these rules and the cache. The cache notes in docs/plugins/create/howto.md and docs/guides/configuration.md, English and Chinese, say that a search with plugin arguments is not cached.

Tests:

  • Search is added to the commands the CLI tests run.
  • CLI tests for dash arguments, a plain debug argument, the -- forms, the help flags in each spelling (-h, --h, -help, --help, =true), arguments after -- and SDK names that start with a dash.
  • A CLI test with a plugin that counts its calls: a warm cache, two --no-cache calls and a plain search after the plugin removed the cache.
  • TestDebugFlagCLI runs vfox list with --debug, --debug=true and --debug=false. main now fixes --debug=false in cmd/cmd.go itself, so the branch keeps its version and only adds the test.
  • TestSearchHelpLeavesOutTheVersionFlag runs vfox search --help with the real root flags and checks that print version is not listed.
  • CLI and table tests for an empty SDK name ("" echo x and "" --no-cache): exit 1 and "sdk name is required".
  • A table test for searchArgs, compared with slices.Equal.

go test ./..., go vet ./cmd/... and gofmt -l on the changed files pass.

vfox search parsed the arguments after the SDK name as flags, so vfox search clang --no-cache failed with "flag provided but not defined". The command now skips flag parsing and hands every argument to the Available hook. -h and --help still print the same help, and a leading -- is still dropped.
Copilot AI balanced review requested due to automatic review settings November 21, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@linghengqian linghengqian added this to the 1.1.1 milestone Nov 21, 2026
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.68293% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.69%. Comparing base (75884c1) to head (4d7409f).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
cmd/commands/search.go 95.00% 1 Missing and 1 partial ⚠️
internal/sdk/sdk.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #813      +/-   ##
==========================================
+ Coverage   63.15%   63.69%   +0.54%     
==========================================
  Files         125      125              
  Lines        9906     9983      +77     
==========================================
+ Hits         6256     6359     +103     
+ Misses       3119     3083      -36     
- Partials      531      541      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@linghengqian linghengqian self-assigned this Nov 21, 2026

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this. The dash case works now, and the new test fails on main, so it covers the bug.

I compared this branch with main on a set of vfox search calls. A few behave differently, and I'd like to hear what you intended, since you know the design best.

On main, vfox search -- clang --no-cache works. In this PR it fails with -- not supported. Is it intended that a -- before the SDK name no longer works? Some scripts pass -- before their arguments.

On main, vfox search clang --debug turns on debug logging. In this PR the option goes to the plugin instead, and vfox search --debug clang fails. vfox --debug search clang still works. Should --debug keep working inside vfox search? If so, how would you separate vfox's own options from the plugin's arguments?

On main, vfox search clang --help prints No help topic for 'clang'. In this PR the flag goes to the plugin. What should a help flag after the SDK name mean? One option is that help flags are read before a --, and everything after -- belongs to the plugin, as in vfox search clang -- --help.

On main, vfox search clang --debug=maybe is an error. In this PR the value goes to the plugin. Should an invalid value for vfox's own flags stay an error?

The root --debug flag also ignores its value, so vfox --debug=false list turns debug logging on on main. This PR changes how --debug is read, so it may make sense to handle that here as well. What do you think?

The PR description says -h and --help print the same help as before. That holds only when the flag comes first. Once the behavior is settled, the description could say which rules apply.

The new tests cover arguments after the SDK name. Cases for a -- before the SDK name and for --debug might be worth adding.

@linghengqian linghengqian removed their assignment Nov 21, 2026
…ugin

-h, --help and --debug keep working anywhere before a --. Every other argument after the SDK name goes to the plugin, and everything after a -- does. An invalid --debug value is an error again, and the root --debug=false no longer turns debug logging on.
@mateuscmtropical

Copy link
Copy Markdown
Contributor Author

Thanks for comparing them. None of those changes were intended. I pushed a change so that vfox reads its own options before a -- and the plugin gets the rest:

  • vfox search -- clang --no-cache works again.
  • --debug works anywhere before a --, so vfox search clang --debug and vfox search --debug clang turn on debug logging.
  • -h and --help before a -- print the search help, also after the SDK name. vfox search clang -- --help passes it to the plugin.
  • vfox search clang --debug=maybe is an error again.
  • The root --debug now uses its value, so vfox --debug=false list leaves debug logging off.

I added tests for -- before the SDK name, for help and debug after --, and a table test for the argument split. I also updated the description with the rules.

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up. Most of the earlier points are handled in dfa3ac1. vfox search -- echo --no-cache and vfox search echo -- --no-cache both work, --debug and -h/--help are read before a --, an invalid --debug value is an error again, vfox search clang --help shows the search help, and the PR description now lists the rules. CI is green, and go test ./... passes on this commit.

Two items are still open.

  1. No test for the root --debug=false change. cmd/cmd.go now enables debug logging only when --debug is true, but no test covers that. Please add a CLI test showing that vfox --debug=false list prints no debug output (for example, no Loading all SDKs from line), and that vfox --debug list still prints it. On main, --debug=false turns the debug output on, so the test should fail there. AGENTS.md asks for tests with behavior changes.

  2. -v, -V and --version after the SDK name are not described. On main, vfox search echo -v prints the vfox version. On this branch the flag goes to the plugin (vfox search echo -v lists -v as a version), and vfox search --version is taken as the SDK name and fails. Please either describe this in the rules, or treat these flags as vfox options before --, the way -h and --debug are handled. I'd prefer the first, since "everything after the SDK name goes to the plugin" already covers them, but the rules should say which one applies.

I'm requesting changes for these two items and will review again after the update.

A CLI test runs vfox list with --debug, --debug=true and --debug=false and checks the debug line. It fails on main for --debug=false. searchArgs now says that -v, -V and --version after the SDK name go to the plugin, with a table case for it.
@mateuscmtropical

Copy link
Copy Markdown
Contributor Author

Thanks. Done in 81cff6c.

  1. TestDebugFlagCLI in cmd/debug_test.go runs vfox list with --debug, --debug=true and --debug=false and checks for the Loading all SDKs from line. With cmd/cmd.go from main it fails on --debug=false.
  2. I went with the first option. The rules in the description and the searchArgs comment now say that -v, -V and --version after the SDK name go to the plugin, and the searchArgs table has a case for it.

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 81cff6c.

Not ready to merge. The main fix works: arguments after the SDK name reach the plugin, and the new tests pass. But there is a regression, a claim in the description that does not hold, and several smaller problems. I count all of them as blocking.

  1. A plain debug argument is read as the debug option.
    searchArgs (cmd/commands/search.go:184) strips the leading dash before it compares names, so the word debug matches name == "debug" with no dash at all. On main, vfox search args x debug y lists x, debug and y. On this branch it lists only x and y, and debug logging turns on. vfox search debug now fails with sdk name is required, so a plugin named debug cannot be searched.
    Fix: only read an argument as an option when it starts with -. Add clang debug and debug cases to TestSearchArgs, and add a CLI test that passes a plugin argument named debug.

  2. --no-cache does not refresh the list, so the description is wrong.
    There are two separate causes.

  • vfox-clang's clearCache() (lib/util.lua on its main branch) removes available.cache, without the leading dot. vfox writes .available.cache (internal/sdk/sdk.go:130), so the file vfox uses is never removed. I reproduced this with a local plugin that copies vfox-clang's Available and clearCache logic: search <plugin> --no-cache followed by search <plugin> still shows the old list. When the copy removes .available.cache, the same sequence shows the new list.
  • vfox reads its cache before it calls the hook, keyed by the joined arguments (sdk.go:145). If a plugin returns a list for a call with --no-cache, that list is cached for 12 hours, and the plugin is not called again with those arguments. I reproduced this with a plugin that returns a new value on each call. The second search <plugin> --no-cache printed the first value.

The first cause is in the plugin. The second is in this PR's area, because this PR is what lets flags such as --no-cache reach the plugin. The description says the README flow works, and it does not. Please pick one approach and say which one in the description:
(a) keep caching by argument list, document that a refresh flag only works if the plugin deletes .available.cache, and fix vfox-clang; or
(b) skip the cache read and write for calls that pass plugin arguments, and state the cost in extra network requests.
Either way, add a test that runs a --no-cache call and then a plain search against a warm cache.

  1. A flag before the SDK name is looked up as an SDK name.
    vfox search --version printed the vfox version on main, and then failed with sdk name is required. On this branch it looks for a plugin called --version. In a terminal the user is asked [--version] not added yet, confirm that you want to use [--version]?. vfox search --no-cache args x does the same with --no-cache. Reject an SDK name that starts with - before any lookup, both before and after --, with a usage error that points to vfox --version.

  2. cmd/debug_test.go is committed with mode 100755. The other test files in cmd/ are 100644. Please reset the mode.

  3. The docs are behind. docs/usage/core-commands.md and docs/zh-hans/usage/core-commands.md describe optionArgs in one line. The new rules need to be written down in both: -h, --help and --debug belong to vfox before a --, and everything after -- goes to the plugin.

  4. TestSearchArgs compares strings.Join(..., " ") (search_cli_test.go:109), so ["a b"] equals ["a", "b"]. Use slices.Equal. The tests do not cover items 1 and 3, which is why they got through.

Checked and fine: CI is green. go vet ./cmd/..., gofmt on the changed files and go test ./cmd/... pass locally. TestDebugFlagCLI fails on main for --debug=false, as the description says. The root --debug=false change is correct. Help output for vfox search and shell completion for search are unchanged.

@mateuscmtropical

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. All six are in 0e94a40.

  1. Only arguments that start with a dash are read as --debug. clang debug, debug and a CLI test with a plugin argument named debug are covered.
  2. I took (b). A search with plugin arguments skips the cache, and the description now says so and states the cost. The new CLI test uses a plugin that counts its calls: two plain searches give call 1 twice, two --no-cache calls give 2 and 3, and the plain search after that gives 4 because the plugin removed .available.cache. With the cache change reverted it fails on the second --no-cache call. The available.cache name in vfox-clang is still wrong, so I can open a PR there if you like.
  3. An SDK name that starts with a dash is now a usage error before any lookup, before and after --, and it points to vfox --version.
  4. cmd/debug_test.go is back to 100644.
  5. Both core-commands.md files describe the rules and the cache.
  6. TestSearchArgs uses slices.Equal and has a "a b" case.

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #813 at 0e94a40

Not ready to merge. Most of the six items from the last review are fixed. Item 1 is the only code bug. Items 2 to 5 are doc and commit message fixes, and they still block the merge.

1. Regression: help spellings that main accepts now fail

On main, each of these prints the search help and exits 0:

vfox search -help
vfox search --h
vfox search --help=true
vfox search -h=true

On this branch each one exits 1 with the sdk name cannot start with a dash. searchArgs in cmd/commands/search.go matches only the exact strings -h and --help. It does not apply the name and =value parsing it uses for --debug. urfave's flag parser accepts the other spellings for bool flags, which is why main handled them.

Parse the help flag the same way as --debug: names h and help, one or two dashes, optional =value. Add a TestSearchArgs case for each spelling, and a CLI test for at least -help and --help=true.

2. The -- rule in the docs is wrong

Both docs/usage/core-commands.md and docs/zh-hans/usage/core-commands.md say every argument after a -- goes to the plugin. When the SDK name comes after the --, it does not. vfox search -- echo --no-cache looks up echo and passes only --no-cache to the plugin. The comment in searchArgs has the right rule. Make the docs say the same.

3. -debug is undocumented

searchArgs reads -debug and -debug=<bool> as vfox's debug flag. The docs name only --debug, and they say every other argument goes to the plugin. Document the single-dash form in both files. Keep the behavior, because main also turned on debug output for vfox search echo -debug.

4. The plugin docs describe the old cache behavior

docs/plugins/create/howto.md says vfox caches the results of the Available hook (English around line 134, Chinese around line 125). Calls with plugin arguments are not cached anymore. Say so in both places, and in the cache section of docs/guides/configuration.md if it fits there.

5. Commit subject

0e94a40 is titled "fix: address the second search review". The subject names a review, not the change. Reword it, or squash the branch before merge with a subject that says what changed.

Checked and correct at 0e94a40

  • Each of the six items from the last review has a change. The docs part is incomplete, as items 2 to 4 show.
  • go test ./... passes with HOME set to a scratch directory. go vet ./cmd/... and gofmt -l report nothing for the changed files.
  • TestDebugFlagCLI fails on main's cmd/cmd.go at --debug=false, as the description says.
  • These behave as documented: vfox search -- echo --no-cache, vfox search echo -- --no-cache, vfox search -- --help (usage error), vfox search echo -- --help --debug (both go to the plugin), vfox search debug (looks up a plugin named debug), vfox --debug=false list.
  • With a plugin that counts its calls and deletes .available.cache on --no-cache, the sequence plain, plain, --no-cache, --no-cache, plain gives call-1, call-1, call-2, call-3, call-4.
  • Shell completion for search, vfox help search and vfox --version match main. cmd/debug_test.go is mode 100644.

Please fix items 1 to 4, add the help-spelling tests, and reword or squash the commit in item 5. Then request a new review.

Only arguments that start with a dash are read as --debug, so a plain debug goes to the plugin or names the SDK. An SDK name that starts with a dash is a usage error before any lookup. A search with plugin arguments skips the Available cache, so a refresh flag such as --no-cache reaches the plugin every time. TestSearchArgs compares with slices.Equal. The search docs in English and Chinese describe the rules and the cache. cmd/debug_test.go is back to mode 100644.
Before a --, search reads -h, -help and -debug with one or two dashes and an optional =value, as the flag parser did on main. So -help, --h, -h=true and --help=true print the help again. TestSearchArgs and the help CLI test cover each spelling.

The search docs say that an SDK name after a -- is still the SDK name, and name -debug. The plugin and configuration docs say that a search with plugin arguments is not cached.
@mateuscmtropical

Copy link
Copy Markdown
Contributor Author

Thanks. All five are in a38311a and 55404aa.

  1. searchArgs reads h, help and debug with one or two dashes and an optional =value. -help, --h, -h=true and --help=true print the help again. TestSearchArgs has a case for each, plus --help=false and an invalid value. TestSearchStillShowsItsHelp runs -help, --help=true, --h and -h=true. Both tests fail with the previous search.go.
  2. Both core-commands.md files now say that an SDK name after a -- is still the SDK name, with vfox search -- clang --help as an example.
  3. The same paragraph names -debug and says that each option also works with two dashes and with a value.
  4. howto.md and the cache section of configuration.md, English and Chinese, say that a search with plugin arguments is not cached.
  5. I reworded 0e94a40 to "fix: skip the search cache with plugin arguments, read only dashed debug" (now a38311a) and force pushed.

go test ./... and go vet ./cmd/... pass, and gofmt -l reports nothing for the changed files.

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ready to merge. Three items block it.

  1. An empty SDK name is dropped, so the next argument becomes the SDK name.

searchArgs uses opts.sdkName == "" to mean "no SDK name yet". An empty argument leaves that empty, and the next argument takes its place (search.go:201-207, and the check at 225). Main rejects this; this branch does not:

  • vfox search "" echo x: main prints "sdk name is required". This branch lists the versions of echo.
  • vfox search "" --no-cache: the error says --no-cache cannot start with a dash, which is not the real problem.

A script with an unset variable (vfox search "$sdk" 21) now looks up 21 as the SDK name instead of stopping. Keep a separate bool for "SDK name seen", so an empty name stays an empty name and fails with "sdk name is required". Add a TestSearchArgs case for the arguments "" echo, and a CLI test that expects exit 1 and "sdk name is required".

  1. search --help still lists -v, -V and --version as global options.

The help prints "--version, -v, -V print version" under GLOBAL OPTIONS. The flag comes from cmd/cmd.go:49 and the help is printed at search.go:219. On this branch, vfox search echo -v sends -v to the plugin, and vfox search -v is an error. Make the help match: leave the version flag out of search's help, or print a search-specific help. TestSearchStillShowsItsHelp should also check that the output does not contain "print version".

  1. The usage docs contradict themselves.

docs/usage/core-commands.md:16 and docs/zh-hans/usage/core-commands.md:16 say every argument after the SDK name goes to the plugin, "-v and --version included". The same paragraph says a few words earlier that -h, -help and -debug are read by vfox wherever they are. vfox search echo --debug and vfox search echo --help do not reach the plugin, so the sentence is wrong. Suggested wording: "Apart from -h, -help and -debug, every argument after the SDK name goes to the plugin, -v and --version included." Same fix in the Chinese page.

Checked and fine at 55404aa:

  • go test ./... passes with HOME set to a scratch directory. go vet ./cmd/... is clean. CI was green when I checked.
  • TestDebugFlagCLI fails on main for --debug=false, as the description says. The cmd/cmd.go change is correct.
  • Shell completion output for search matches main in every case I tried.
  • search -- echo --help, search echo -- --help and search echo -- -- y behave as the docs say.
  • search echo --debug x and search echo --debug=false x do what they should. A root --debug=false no longer turns logging on.
  • Plain searches (no plugin arguments) still use the cache.
  • gofmt -l reports internal/plugin/model_test.go. That file is not part of this PR, and main reports the same.

Ping me when these are in and I will take another look.

@mateuscmtropical

Copy link
Copy Markdown
Contributor Author

Thanks. All three are in 1c025db, and 64ba676 merges main.

  1. searchArgs keeps a separate "SDK name seen" flag, so an empty name stays empty. vfox search "" echo x and vfox search "" --no-cache exit 1 with "sdk name is required". TestSearchArgs has the "" echo case and TestSearchRejectsAnEmptySDKName checks both at the CLI.
  2. search --help uses its own template that skips the version flag under GLOBAL OPTIONS. --debug is still listed. The in-process test app has no version flag, so the check is in cmd/debug_test.go (TestSearchHelpLeavesOutTheVersionFlag), which runs the real root. It fails with the previous search.go.
  3. Both core-commands.md pages use your wording.

The merge had two conflicts. In cmd/cmd.go I took main's --debug handler, which already leaves debug off for --debug=false. TestDebugFlagCLI passes with it. In cli_test.go the pristine list now has the new commands from main plus Search.

go test ./..., go vet ./cmd/... and gofmt -l cmd/ pass.

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ready to merge at 1c025db.

The three points from my last review are fixed. An empty SDK name stops with "sdk name is required". search --help lists only --debug under GLOBAL OPTIONS. The usage docs say which options vfox reads and which go to the plugin.

One item is left. AGENTS.md line 95 still says:

- `Available(args)` caches by arguments in the plugin's `.available.cache`. Preserve `AvailableHookDuration` semantics: `0` disables caching and `-1` means no expiry.

This branch changes that. With plugin arguments, Available neither reads nor writes the cache (internal/sdk/sdk.go:152, if cacheDuration == 0 || len(args) > 0). AGENTS.md asks that behavior descriptions match the implementation, so the line has to change in this PR, for example:

- `Available(args)` caches only calls without arguments, in the plugin's `.available.cache`. A call with arguments, such as `vfox search <sdk> --no-cache`, reads and writes no cache and calls the hook every time. Preserve `AvailableHookDuration` semantics: `0` disables caching and `-1` means no expiry.

On this head I checked with a binary: a plain search is cached, a search with arguments calls the plugin each time, and a search with arguments does not replace the cached plain result.

@mateuscmtropical

Copy link
Copy Markdown
Contributor Author

Thanks. Done in 4d7409f with your wording. AGENTS.md now says that Available(args) caches only calls without arguments.

@linghengqian linghengqian added the bug Something isn't working label Nov 27, 2026

@linghengqian linghengqian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@linghengqian
linghengqian merged commit c62ce67 into version-fox:main Nov 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search does not pass arguments that start with a dash to plugins

3 participants