-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
126 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/lib | ||
/test/fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {Hooks, IHook} from '@dxcli/config' | ||
import {color} from '@heroku-cli/color' | ||
import cli from 'cli-ux' | ||
|
||
const hook: IHook<Hooks['command_not_found']> = async opts => { | ||
function closest(cmd: string) { | ||
const DCE = require('string-similarity') | ||
return DCE.findBestMatch(cmd, opts.config.engine.commandIDs).bestMatch.target | ||
} | ||
|
||
let binHelp = `${opts.config.bin} help` | ||
let idSplit = opts.id.split(':') | ||
if (await opts.config.engine.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` : '' | ||
cli.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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@dxcli/test-not-found", | ||
"version": "0.0.0", | ||
"dxcli": { | ||
"bin": "mycli", | ||
"plugins": ["../.."], | ||
"commands": "./src/commands" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"files": [ | ||
"/src" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const {Command, flags} = require('@dxcli/command') | ||
const {cli} = require('cli-ux') | ||
|
||
class CLI extends Command { | ||
async run() { | ||
const name = this.flags.name || 'world' | ||
cli.log(`hello ${name}!`) | ||
} | ||
} | ||
|
||
CLI.flags = { | ||
name: flags.string({char: 'n', description: 'name to print'}), | ||
} | ||
|
||
module.exports = CLI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {describe, expect, testHook} from '@dxcli/dev-test' | ||
import color from '@heroku-cli/color' | ||
import * as path from 'path' | ||
|
||
color.enabled = false | ||
|
||
const root = path.join(__dirname, '../fixtures/test') | ||
|
||
describe('command', () => { | ||
testHook('command_not_found', {id: 'hel'}, {root, stderr: true, exit: 127}, ({error}) => { | ||
expect(error!.message).to.equal(`hel is not a mycli command. | ||
Perhaps you meant hello | ||
Run mycli help for a list of available commands.`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters