【发布时间】:2015-01-15 05:22:02
【问题描述】:
当您键入非法的npm 命令时,您会收到一条用户友好的错误消息,说明哪些命令可以合法使用:
$ npm illegal
Usage: npm <command>
where <command> is one of:
add-user, adduser, apihelp, author, bin, bugs, c, cache,
completion, config, ddp, dedupe, deprecate, docs, edit,
explore, faq, find, find-dupes, get, help, help-search,
home, i, info, init, install, isntall, issues, la, link,
list, ll, ln, login, ls, outdated, owner, pack, prefix,
prune, publish, r, rb, rebuild, remove, repo, restart, rm,
root, run-script, s, se, search, set, show, shrinkwrap,
star, stars, start, stop, submodule, tag, test, tst, un,
uninstall, unlink, unpublish, unstar, up, update, v,
version, view, whoami
您可能会注意到,其中有 isntall 命令。
这个命令有什么意义?如果这是为了处理拼写错误而创建的,那么为什么不对intall、insatll 等进行特殊处理?此外,uninstall 没有对应的unisntall 选项。
(使用 npm 1.3.22 版本)。
我问的原因是我对如何处理拼写错误感到有点惊讶和困惑。例如,git 会比较您输入的命令并建议其可用的最接近的命令:
$ git stats
git: 'stats' is not a git command. See 'git --help'.
Did you mean this?
status
另外,pip Python package manager 内置了类似的功能:
$ pip isntall
ERROR: unknown command "isntall" - maybe you meant "install"
仅供参考,under-the-hood 它使用 difflib.get_close_matches() 函数。
【问题讨论】:
-
这是为了提醒你 npm 不是那么回事。
-
OP,你应该用谷歌搜索你的问题。这是我在 npm 的 github 页面上对关键字“isntall”的第一个结果。 github.com/npm/npm/issues/2933
-
有趣的事实:最新版本的 npm 仍然接受
isntall作为别名,但它不再在该列表中显示它以免混淆人们。我个人认为有这样一个别名简直是愚蠢的,但从 Github 问题来看,他们不希望有更多的反馈。 -
@alecxe:我猜你的代表已经知道“你怎么看?”-问题是题外话?你可能会在聊天中提出这样的事情。
-
这可能在全球范围内节省了数百万小时,然后被人们开始研究异常并编写像这样的 cmets 浪费掉了
标签: javascript node.js npm package-managers