Repository navigation
fix: pass search arguments that start with a dash to the plugin - #813
Conversation
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.
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
linghengqian
left a comment
There was a problem hiding this comment.
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.
…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.
|
Thanks for comparing them. None of those changes were intended. I pushed a change so that vfox reads its own options before a
I added tests for |
linghengqian
left a comment
There was a problem hiding this comment.
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.
-
No test for the root
--debug=falsechange.cmd/cmd.gonow enables debug logging only when--debugis true, but no test covers that. Please add a CLI test showing thatvfox --debug=false listprints no debug output (for example, noLoading all SDKs fromline), and thatvfox --debug liststill prints it. Onmain,--debug=falseturns the debug output on, so the test should fail there. AGENTS.md asks for tests with behavior changes. -
-v,-Vand--versionafter the SDK name are not described. Onmain,vfox search echo -vprints the vfox version. On this branch the flag goes to the plugin (vfox search echo -vlists-vas a version), andvfox search --versionis taken as the SDK name and fails. Please either describe this in the rules, or treat these flags as vfox options before--, the way-hand--debugare 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.
|
Thanks. Done in 81cff6c.
|
linghengqian
left a comment
There was a problem hiding this comment.
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.
-
A plain
debugargument is read as the debug option.
searchArgs(cmd/commands/search.go:184) strips the leading dash before it compares names, so the worddebugmatchesname == "debug"with no dash at all. On main,vfox search args x debug ylistsx,debugandy. On this branch it lists onlyxandy, and debug logging turns on.vfox search debugnow fails withsdk name is required, so a plugin nameddebugcannot be searched.
Fix: only read an argument as an option when it starts with-. Addclang debuganddebugcases to TestSearchArgs, and add a CLI test that passes a plugin argument nameddebug. -
--no-cachedoes 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) removesavailable.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'sAvailableandclearCachelogic:search <plugin> --no-cachefollowed bysearch <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 secondsearch <plugin> --no-cacheprinted 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.
-
A flag before the SDK name is looked up as an SDK name.
vfox search --versionprinted the vfox version on main, and then failed withsdk 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 xdoes 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 tovfox --version. -
cmd/debug_test.go is committed with mode 100755. The other test files in cmd/ are 100644. Please reset the mode.
-
The docs are behind. docs/usage/core-commands.md and docs/zh-hans/usage/core-commands.md describe
optionArgsin one line. The new rules need to be written down in both:-h,--helpand--debugbelong to vfox before a--, and everything after--goes to the plugin. -
TestSearchArgs compares
strings.Join(..., " ")(search_cli_test.go:109), so["a b"]equals["a", "b"]. Useslices.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.
|
Thanks for the detailed review. All six are in 0e94a40.
|
linghengqian
left a comment
There was a problem hiding this comment.
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/...andgofmt -lreport nothing for the changed files.TestDebugFlagCLIfails on main'scmd/cmd.goat--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.cacheon--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 searchandvfox --versionmatch main.cmd/debug_test.gois 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.
0e94a40 to
55404aa
Compare
|
Thanks. All five are in a38311a and 55404aa.
|
linghengqian
left a comment
There was a problem hiding this comment.
Not ready to merge. Three items block it.
- 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".
- 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".
- 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.
# Conflicts: # cmd/cmd.go # cmd/commands/cli_test.go
|
Thanks. All three are in 1c025db, and 64ba676 merges
The merge had two conflicts. In
|
linghengqian
left a comment
There was a problem hiding this comment.
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.
|
Thanks. Done in 4d7409f with your wording. AGENTS.md now says that |
Fixes #808
vfox searchnow reads its own options and hands every other argument after the SDK name to the plugin'sAvailablehook, including the ones that start with a dash. Sovfox search clang --no-cachereaches the plugin.The rules (
searchArgsincmd/commands/search.go):--, vfox reads-h,-helpand-debugwherever they are, each with one or two dashes and an optional=value, as the flag parser did onmain. Only arguments that start with a dash count, so a plaindebuggoes to the plugin or names the SDK. An invalid value is an error, as onmain.vfox search "" echofails with "sdk name is required" as onmain.-v,-Vand--versionare not vfox options insearch. After the SDK name they go to the plugin like any other argument, andsearch --helpdoes not list them.vfox --versionstill prints the version.--. The message points tovfox --version.--, every argument goes to the plugin, help and debug flags included, except the SDK name when it comes after the--. Sovfox search clang -- --helpasks the plugin, andvfox search -- clang --no-cacheandvfox search clang -- --no-cachekeep working.Cache: a search with plugin arguments skips the
Availablecache, 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-cacheshould also delete.available.cachein its directory, so the next plain search is fresh. vfox-clang removesavailable.cachewithout 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.mdanddocs/zh-hans/usage/core-commands.mddescribes these rules and the cache. The cache notes indocs/plugins/create/howto.mdanddocs/guides/configuration.md, English and Chinese, say that a search with plugin arguments is not cached.Tests:
Searchis added to the commands the CLI tests run.debugargument, the--forms, the help flags in each spelling (-h,--h,-help,--help,=true), arguments after--and SDK names that start with a dash.--no-cachecalls and a plain search after the plugin removed the cache.TestDebugFlagCLIrunsvfox listwith--debug,--debug=trueand--debug=false.mainnow fixes--debug=falseincmd/cmd.goitself, so the branch keeps its version and only adds the test.TestSearchHelpLeavesOutTheVersionFlagrunsvfox search --helpwith the real root flags and checks thatprint versionis not listed."" echo xand"" --no-cache): exit 1 and "sdk name is required".searchArgs, compared withslices.Equal.go test ./...,go vet ./cmd/...andgofmt -lon the changed files pass.