celeri
celeri copied to clipboard
TypeError if command name contains dashes
Using [email protected]
Basically, I want to add a --version
flag, without specifying a command.
The README.md file shows the following usage/help:
Usage: [command] --arg=value --arg2
Not sure if that means that I can have an optional command, or not, but so far I'm struggling to make it work. I want to call something like this from the CLI (and have it return the semver version
string from my package.json file):
$ node index.js --version
Steps to reproduce:
// index.js
var celeri = require("celeri");
console.log(process.argv);
// A:
/*
celeri.option("--version", function (data) {
console.log(data);
});
celeri.parse(process.argv);
*/
// B:
celeri.option({
command: '--version',
description: 'shows the current version'
}, function (data) {
var version = require("./package.json").version;
console.log(version);
console.log(data);
});
celeri.parse(process.argv);
Actual results:
$ node index --version
[ 'node',
'/Users/pdehaan/dev/tmp/celeri-tmp/index',
'--version' ]
/Users/pdehaan/dev/tmp/celeri-tmp/node_modules/celeri/lib/plugins/argv/index.js:31
ops.name = mainCmd.path.segments[0].value;
^
TypeError: Cannot read property 'path' of undefined
at Object.cli.option (/Users/pdehaan/dev/tmp/celeri-tmp/node_modules/celeri/lib/plugins/argv/index.js:31:21)
at Object.<anonymous> (/Users/pdehaan/dev/tmp/celeri-tmp/index.js:14:8)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Looks like somewhere in the bowels of the code (lib/plugins/argv/index.js:31) there isn't a null check:
28: var mainCmd = cli.parseCommand(ops.command).shift();
29:
30:
31: ops.name = mainCmd.path.segments[0].value;
32: ops.usage = ops.usage || ops.command;
Workaround:
I can switch the command option from --version
to version
, but that doesnt seem very consistent w/ calling npm --version
or node -v
or sass --version
or scss-lint --version
:
$ node index version
[ 'node', '/Users/pdehaan/dev/tmp/celeri-tmp/index', 'version' ]
0.0.1
{}