请教大佬一个问题, 在项目文件夹里面, 如果直接用`node bin/cli fly in sky`来查词会报错, 百思不得其解, 详情见内容.
zhoujin7 opened this issue · comments
zhoujin7 commented
环境信息
- 系统及版本: Windows 10 1909
- Node 版本: nodejs 12.18.4
- 终端软件及版本: cmd
- EazyDict 版本: 2.1.0
问题描述:
在bin/cli里面的如下代码加一句console.log(argus);
, 如果直接用node bin/cli fly in sky
来查词会报错.
/**
* 主程序
*/
program
.usage('<words...>')
.description('简单易用的命令行词典 https://github.com/keenwon/eazydict')
.option('-s, --save', '查询单词,同时保存到生词本')
.option('-r, --raw', '不转换为小写,查询原始的输入值')
.action(function (...argus) {
// 在这里加一句打印argus
console.log(argus);
const words = argus.slice(0, -1);
const options = {
save: program.save || false,
raw: program.raw || false
};
lookup(words, options);
});
直接用node bin/cli fly in sky
来查词, 输出的argus如下:
[
Command {
_events: [Object: null prototype] {
'option:save': [Function],
'option:raw': [Function],
'--help': [Function]
},
_eventsCount: 3,
_maxListeners: undefined,
commands: [
[Command],
[Command],
[Command],
[Command],
[Command],
[Command],
[Command]
],
options: [ [Option], [Option] ],
parent: null,
_allowUnknownOption: false,
_args: [],
rawArgs: [
'C:\\Users\\jin7\\scoop\\apps\\nodejs-lts\\current\\node.exe',
'C:\\development\\jsdev\\eazydict-origin\\bin\\cli',
'fly',
'in',
'sky'
],
_scriptPath: 'C:\\development\\jsdev\\eazydict-origin\\bin\\cli',
_name: 'cli',
_optionValues: {},
_storeOptionsAsProperties: true,
_storeOptionsAsPropertiesCalled: false,
_passCommandToAction: true,
_actionResults: [],
_actionHandler: [Function: listener],
_executableHandler: false,
_executableFile: null,
_defaultCommandName: null,
_exitCallback: null,
_aliases: [],
_combineFlagAndOptionalValue: true,
_hidden: false,
_hasHelpOption: true,
_helpFlags: '-h, --help',
_helpDescription: 'display help for command',
_helpShortFlag: '-h',
_helpLongFlag: '--help',
_hasImplicitHelpCommand: false,
_helpCommandName: 'help',
_helpCommandnameAndArgs: 'help [command]',
_helpCommandDescription: 'display help for command',
program: [Circular],
Command: [class Command extends EventEmitter],
Option: [class Option],
CommanderError: [class CommanderError extends Error],
_usage: '<words...>',
_description: '简单易用的命令行词典 https://github.com/keenwon/eazydict',
_argsDescription: undefined,
args: [ 'fly', 'in', 'sky' ],
[Symbol(kCapture)]: false
},
[ 'fly', 'in', 'sky' ]
]
通过npm install -g eazydict
安装的, 用eazydict fly in sky
来查词, 输出的argus如下:
[
'fly',
'in',
'sky',
Command {
commands: [
[Command],
[Command],
[Command],
[Command],
[Command],
[Command],
[Command]
],
options: [ [Option], [Option] ],
_execs: {},
_allowUnknownOption: false,
_args: [],
_name: 'cli',
Command: [Function: Command],
Option: [Function: Option],
_usage: '<words...>',
_description: '简单易用的命令行词典 https://github.com/keenwon/eazydict',
_argsDescription: undefined,
_events: [Object: null prototype] {
'option:save': [Function],
'option:raw': [Function],
'command:*': [Function: listener],
'command:lookup': [Function: listener],
'command:l': [Function: listener],
'command:version': [Function: listener],
'command:v': [Function: listener],
'command:history': [Function: listener],
'command:h': [Function: listener],
'command:save': [Function: listener],
'command:s': [Function: listener],
'command:install': [Function: listener],
'command:i': [Function: listener],
'command:wordbook': [Function: listener],
'command:w': [Function: listener],
'command:status': [Function: listener],
'--help': [Function]
},
_eventsCount: 17,
rawArgs: [
'C:\\Users\\jin7\\scoop\\apps\\nodejs-lts\\current\\node.exe',
'C:\\Users\\jin7\\scoop\\apps\\nodejs-lts\\current\\bin\\node_modules\\eazydict\\bin\\cli',
'fly',
'in',
'sky'
],
args: [ 'fly', 'in', 'sky', [Circular] ]
}
]
百思不得其解, 不知道为什么会这样? 直接在项目文件夹里面用node bin/cli fly in sky
来查词, 输出argus和全局安装的不同.
我看了commander的文档, 也不知道为何.
原谅我是菜鸟, 愿意打赏一下大佬.
Keenwon commented
用 git bash 试一试,有错误信息发出来
zhoujin7 commented
(node:1476) UnhandledPromiseRejectionWarning: TypeError: word.trim is not a function
at C:\development\jsdev\eazydict-origin\src\lookup.js:24:23
at Array.map (<anonymous>)
at lookup (C:\development\jsdev\eazydict-origin\src\lookup.js:24:6)
at Command.<anonymous> (C:\development\jsdev\eazydict-origin\bin\cli:31:5)
at Command.listener [as _actionHandler] (C:\development\jsdev\eazydict-origin\node_mod
ules\commander\index.js:426:31)
at Command._parseCommand (C:\development\jsdev\eazydict-origin\node_modules\commander\
index.js:1002:14)
at Command.parse (C:\development\jsdev\eazydict-origin\node_modules\commander\index.js
:801:10)
at Object.<anonymous> (C:\development\jsdev\eazydict-origin\bin\cli:151:9)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
(node:1476) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error orig
inated either by throwing inside of an async function without a catch block, or by rejecti
ng a promise which was not handled with .catch(). To terminate the node process on unhandl
ed promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs
.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1476) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In
the future, promise rejections that are not handled will terminate the Node.js process wit
h a non-zero exit code.
Keenwon commented
估计是 commander 升级造成的,cli 要重写下
zhoujin7 commented
难怪了 我才注意到这个
const words = argus.slice(0, -1);
改成这样就行了const words = argus[1];