-
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
5 changed files
with
99 additions
and
1,078 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
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 |
---|---|---|
@@ -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 |
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
Oops, something went wrong.