From 790e92db9f039093503532a1b191b2151b39c2a7 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 10 Jul 2023 14:19:16 -0600 Subject: [PATCH 1/4] fix: identify when the command is meant to be 'help' --- src/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6c440f12..a5885799 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,7 +21,9 @@ const hook: Hook.CommandNotFound = async function (opts) { binHelp = `${binHelp} ${idSplit[0]}` } - const suggestion = closest(opts.id, commandIDs) + // alter the suggestion in the help scenario so that help is the first command + // otherwise the user will be presented 'did you mean 'help'?' instead of 'did you mean "help "?' + let suggestion = /:?help:?/.test(opts.id) ? ['help', closest(opts.id.replace(/:?help:?/, ''), commandIDs)].join(':') : closest(opts.id, commandIDs) const readableSuggestion = toConfiguredId(suggestion, this.config) const originalCmd = toConfiguredId(opts.id, this.config) @@ -38,7 +40,16 @@ const hook: Hook.CommandNotFound = async function (opts) { if (response === 'y') { // this will split the original command from the suggested replacement, and gather the remaining args as varargs to help with situations like: // confit set foo-bar -> confit:set:foo-bar -> config:set:foo-bar -> config:set foo-bar - const argv = opts.argv?.length ? opts.argv : opts.id.split(':').slice(suggestion.split(':').length) + let argv = opts.argv?.length ? opts.argv : opts.id.split(':').slice(suggestion.split(':').length) + + if (suggestion.startsWith('help:')) { + // the args are the command/partial command you need help for (package:version) + // we created the suggestion variable to start with "help" so slice the first entry + argv = [...suggestion.split(':').slice(1), ...argv] + // the command is just the word "help" + suggestion = 'help' + } + return this.config.runCommand(suggestion, argv) } From 8d46a19e850336f0ecaada53d45659fa4f714b99 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 10 Jul 2023 14:35:09 -0600 Subject: [PATCH 2/4] chore: don't search for topics --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index a5885799..db5d1940 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,7 @@ const hook: Hook.CommandNotFound = async function (opts) { // alter the suggestion in the help scenario so that help is the first command // otherwise the user will be presented 'did you mean 'help'?' instead of 'did you mean "help "?' - let suggestion = /:?help:?/.test(opts.id) ? ['help', closest(opts.id.replace(/:?help:?/, ''), commandIDs)].join(':') : closest(opts.id, commandIDs) + let suggestion = /:?help:?/.test(opts.id) ? ['help', ...opts.id.split(':').filter(cmd => cmd !== 'help')].join(':') : closest(opts.id, commandIDs) const readableSuggestion = toConfiguredId(suggestion, this.config) const originalCmd = toConfiguredId(opts.id, this.config) From fbc5ad4453a7f52728eb65d4173a76f50facdddd Mon Sep 17 00:00:00 2001 From: mshanemc Date: Tue, 11 Jul 2023 11:29:52 -0500 Subject: [PATCH 3/4] docs: readme for developing --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 46aa0325..51a4edaf 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,14 @@ "did you mean" for oclif [![Version](https://img.shields.io/npm/v/@oclif/plugin-not-found.svg)](https://npmjs.org/package/@oclif/plugin-not-found) -[![CircleCI](https://circleci.com/gh/oclif/plugin-not-found/tree/main.svg?style=svg)](https://circleci.com/gh/oclif/plugin-not-found/tree/main) -[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/plugin-not-found?branch=main&svg=true)](https://ci.appveyor.com/project/heroku/plugin-not-found/branch/main) [![Known Vulnerabilities](https://snyk.io/test/npm/@oclif/plugin-not-found/badge.svg)](https://snyk.io/test/npm/@oclif/plugin-not-found) [![Downloads/week](https://img.shields.io/npm/dw/@oclif/plugin-not-found.svg)](https://npmjs.org/package/@oclif/plugin-not-found) [![License](https://img.shields.io/npm/l/@oclif/plugin-not-found.svg)](https://github.com/oclif/plugin-not-found/blob/main/package.json) + +## Developing + +This plugin works as a hook, so it won't "fire" just from being linked (ex: `plugins link .`) + +To test changes using a CLI that already contains plugin-not-found, build this and copy this repo's `lib/index.js` over your CLI's equivalent. + +ex: `~/.local/share/sf/client/current/node_modules/@oclif/plugin-not-found/lib/index.js` \ No newline at end of file From 4e9aab04a77e4852a9046e31bdecc901a62456c7 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 11 Jul 2023 10:42:42 -0600 Subject: [PATCH 4/4] chore: strip command flags from being passed to help command --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index db5d1940..4fb325bd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,7 +45,7 @@ const hook: Hook.CommandNotFound = async function (opts) { if (suggestion.startsWith('help:')) { // the args are the command/partial command you need help for (package:version) // we created the suggestion variable to start with "help" so slice the first entry - argv = [...suggestion.split(':').slice(1), ...argv] + argv = suggestion.split(':').slice(1) // the command is just the word "help" suggestion = 'help' }