Skip to content

Commit

Permalink
fix: remove cli-ux
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Feb 5, 2018
1 parent 98673d9 commit 1602a58
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1,078 deletions.
31 changes: 11 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,31 @@
"version": "0.1.15",
"author": "Jeff Dickey @jdxcode",
"anycli": {
"commands": "./lib/commands",
"devPlugins": [
"@anycli/plugin-version"
],
"hooks": {
"command_not_found": "./lib/hooks/not_found"
}
"command_not_found": "./lib"
},
"devPlugins": [
"@anycli/plugin-help"
]
},
"bugs": "https://github.com/anycli/plugin-not-found/issues",
"dependencies": {
"@anycli/command": "^1.2.2",
"@anycli/command": "^1.2.5",
"@heroku-cli/color": "^1.1.3",
"cli-ux": "^3.3.13",
"string-similarity": "^1.2.0"
},
"devDependencies": {
"@anycli/config": "^1.0.17",
"@anycli/dev-cli": "^0.1.4",
"@anycli/engine": "^0.3.6",
"@anycli/test": "^0.10.8",
"@anycli/config": "^1.2.1",
"@anycli/dev-cli": "^0.1.6",
"@anycli/plugin-help": "^0.6.3",
"@anycli/test": "^0.10.10",
"@anycli/tslint": "^0.2.5",
"@anycli/version-plugin": "^0.1.18",
"@types/chai": "^4.1.2",
"@types/lodash": "^4.14.100",
"@types/mocha": "^2.2.48",
"@types/nock": "^9.1.2",
"@types/node": "^9.4.0",
"@types/node-notifier": "^0.0.28",
"@types/read-pkg": "^3.0.0",
"@types/supports-color": "^3.1.0",
"chai": "^4.1.2",
"concurrently": "^3.5.1",
"eslint": "^4.17.0",
"eslint-config-anycli": "^1.3.2",
"mocha": "^5.0.0",
"ts-node": "^4.1.0",
"typescript": "^2.7.1"
Expand All @@ -58,7 +49,7 @@
"repository": "anycli/plugin-not-found",
"scripts": {
"build": "rm -rf lib && tsc",
"lint": "concurrently -p command \"eslint .\" \"tsc -p test --noEmit\" \"tslint -p test\"",
"lint": "concurrently -p command \"tsc -p test --noEmit\" \"tslint -p test\"",
"postpublish": "rm .anycli.manifest.json",
"posttest": "yarn run lint",
"prepublishOnly": "yarn run build && anycli-dev manifest",
Expand Down
30 changes: 0 additions & 30 deletions src/hooks/not_found.ts

This file was deleted.

32 changes: 29 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
// this file is just here to make typescript not flatten the outDir
// we can't use rootDir as this doesn't allow us to use linked plugins typescript files
export default {}
import {Hook} from '@anycli/config'
import {color} from '@heroku-cli/color'

const hook: Hook<'command_not_found'> = async function (opts) {
const commandIDs = opts.config.commandIDs
if (!commandIDs.length) return
function closest(cmd: string) {
const DCE = require('string-similarity')
return DCE.findBestMatch(cmd, commandIDs).bestMatch.target
}

let binHelp = `${opts.config.bin} help`
let idSplit = opts.id.split(':')
if (await opts.config.findTopic(idSplit[0])) {
// if valid topic, update binHelp with topic
binHelp = `${binHelp} ${idSplit[0]}`
// if topic:COMMAND present, try closest for id
// if (idSplit[1]) closest = this.closest(id)
}

let perhaps = closest ? `Perhaps you meant ${color.yellow(closest(opts.id))}\n` : ''
this.error(
`${color.yellow(opts.id)} is not a ${opts.config.bin} command.
${perhaps}Run ${color.cmd(binHelp)} for a list of available commands.`,
{exit: 127},
)
}

export default hook
2 changes: 1 addition & 1 deletion test/hooks/not_found.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('command', () => {
test
.hook('command_not_found', {id: 'hel'})
.catch(`hel is not a @anycli/plugin-not-found command.
Perhaps you meant version
Perhaps you meant help
Run @anycli/plugin-not-found help for a list of available commands.`)
.end('runs hook')
})
Loading

0 comments on commit 1602a58

Please sign in to comment.