node-js-libs / cli Goto Github PK
View Code? Open in Web Editor NEWRapidly build command line apps
Rapidly build command line apps
hi,
is there a way to retrieve multiple input arguments as a list?
as in when you have something like this:
somecommand -f src/*.coffee
$ node -v
v0.6.12
$ node
typeof null
'object'
This makes the check
if (typeof cli.version === 'undefined') {
cli.parsePackageJson();
}
Fail every time
I've changed it to
if (typeof cli.version === 'undefined' || cli.version == null) {
cli.parsePackageJson();
}
which works, but i'm not sure if its a proper fix, and do you want a pull request?
Hi there. It would be awesome from a distribution packaging point of view if you could include the full text of the MIT license in your software, usually in a file called LICENSE.
Thanks!
The erroneous line appears to be line 891.
file.on('end', function () {
eof = true;
if (data.length) {
callback.apply(cli, [data, sep || '', false]); // line 891
}
callback.apply(cli, [null, null, true]);
});
At the moment, the --help
output will always output the data type of the specified param, if a data type was specified. eg.
Options:
-m, --myparam STRING Does something.
-h, --help Display help and usage details
It would be nice if the "STRING" part could be suppressed as it can look nicer without it. Passing in a value to enable()
to suppress this behaviour would be a nice way to do it.
i'm missing named arguments.
cli.parse({
log: ['l', 'Enable logging'],
},[
['filename', "does something with these files", /*required*/ true, /*list*/ true],
['logfile', "logs into this file"]
],['test', 'run']);
this should result in a help output like:
Usage:
test.js [OPTIONS] filename... [logfile]
Arguments:
filename does something with these files (required)
logfile logs into this file
Options:
-l Enable logging
-h, --help Display help and usage details
Commands:
run, test
setting list=true
for arguments should add a ...
in help and result in an array when parsed.
I'm trying to create options and commands in my script. When the user presses -h , I want Options to appear as well as commands to appear.
Please see the script below, am I going about this the wrong way. It appears cli.parse
can only be used once.
// commands
commands = cli.parse(null, ['showtest']);
// options
options = cli.parse({
file: [ 'f', 'A file to process', 'file', 'temp.log' ], // -f, --file FILE A file to process
time: [ 't', 'An access time', 'time', false], // -t, --time TIME An access time
work: [ false, 'What kind of work to do', 'string', 'sleep' ] // --work STRING What kind of work to do
});
Options:
-h, --host [IP] Host (Default is 127.0.0.1)
-p, --port [NUMBER] Port (Default is 4000)
-s, --ssl BOOLEAN Enable SSL
-t, --transport [STRING]Transport (Default is longPolling)
-n, --number [NUMBER] Number of clients (Default is 1)
-d, --debug BOOLEAN Display debug information
cli.parse({
host : [ 'h', 'Host', 'ip', '127.0.0.1' ],
});
node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Object.parse (/Users/ivanshumkov/Sites/Beseda/vendor/cli/cli.js:264:31)
....
cli.parse({
ccol: ['c', 'C ID column number', 'number', 1],
dryrun: ['n', 'Dry run'],
ocol: ['i', 'O ID column number', 'number', 0],
outfile: ['o', 'Output file', 'path']
});
Options:
-c, --ccol [NUMBER]C ID column number (Default is 1)
-n, --dryrun Dry run
-i, --ocol NUMBER O ID column number
-o, --outfile PATH Output file
-h, --help Display help and usage details
cli.debug(msg)
always prints with no --debug option.
Passing --debug gives ERROR: Unknown option --debug
Please do not use >=
in your glob dependency. There is a change in glob 4.x that is breaking for older versions of npm, and users are getting upset with me about it.
If you do ~3.2.1
, publish a new version, and then bump your master version, and use ^4.0.0
, then all will be well with the world.
Thanks :)
What is the point for options with type "bool", "boolean", "on", "false", "off"? In the options parsing code, I read:
case 'bool': case 'boolean': case 'on':
parsed[opt] = true;
break;
case 'false': case 'off': case false: case 0:
parsed[opt] = false;
break;
Every option of the mentioned type gets a value explicitly assigned, with no checking for defaults, getting a value from the command line. This defies the idea of an "option".
On the documentation I read
cli.parse({
log: ['l', 'Enable logging'],
port: ['p', 'Listen on this port', 'number', 8080],
serve: [false, 'Serve static files from PATH', 'path', './public']
});
To me this means that serve
doesn't have a short flag.
What I see from cli.getUsage()
is
Options:
-l, --log Enable logging
-p, --port [NUMBER] Listen on this port (Default is 8080)
-false, --serve [PATH] Serve static files from PATH (Default is ./public)
-false
on the last line shouldn't be there.
Is there a way to do:
app generate project <project_name>
app generate model <model_name>
because now im forced to do:
app generate-project <project_name>
app generate-model <model_name>
Could you update your package to use the latest version of glob
?
The version currently used by cli
uses an outdated minimatch
which is throwing deprecation warnings:
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
When I enable the 'daemon' plugin and call my script with -d, I get the following stack trace:
TypeError: Object #<Object> has no method 'run'
at /Users/laurie/.node_libraries/.npm/cli/0.2.7/package/cli.js:925:16
at Object.daemon (/Users/laurie/.node_libraries/.npm/cli/0.2.7/package/cli.js:973:9)
at Object.main (/Users/laurie/.node_libraries/.npm/cli/0.2.7/package/cli.js:990:13)
at Object.<anonymous> (/Users/laurie/Projects/node-mud/bin/nmud:23:5)
at Module._compile (module.js:383:26)
at Object..js (module.js:389:10)
at Module.load (module.js:315:31)
at Function._load (module.js:276:12)
at Array.<anonymous> (module.js:402:10)
at EventEmitter._tickCallback (node.js:108:26)
Using:
URL option does not allow us to pass options like www.ipfsbin.xyz because it's checking the TLD to match some arbitrary set of TLDs.
Example code:
#!/usr/bin/env node
var cli = require('../')
cli.parse({
url: ['url', 'An URL', 'url'],
secondurl: ['secondurl', 'An URL', 'url']
})
cli.main(function (args, options) {
console.log(args)
console.log(options)
})
Run with ./script.js --url something.xyz
and options should include that URL but currently throws an exception instead...
Started trying to add something but saw a really scary regex for domain validation and secondly no tests so gave up pretty quickly. But wanted to let you know at least...
It isn't clear from the docs that the option type is required for obtaining anything other than boolean or null from option values.
var cli = require('cli');
cli.parse({
input: ['i', 'Input file']
});
Needs to be:
var cli = require('cli');
cli.parse({
input: ['i', 'Input file', 'path']
});
So a section ought to be dedicated to option types that lists all supported types and makes clear the default option type is boolean.
-k/--no-color and --debug are mutually exclusive. Last one declared wins.
foo -k --debug means debug messages will be output, but with color
foo --debug -k means no debug messages output, and no color
let me know if this was intentional, and I won't bother with a PR
The current code makes use of predictable filenames, in a way that causes a security issue.
I reported this to Debian last year:
It was recently highlighted by the nodesecurity people (six months later!):
Suggested fix:
~/.app.pid
would be better than /tmp
for example.Ever try showing a log file (using --daemon log) that is 100MB in size? For me, it doesn't work so well!
Instead of reading the log file synchronously into memory, how about piping it to stdout or stderr?
pls update README || add cli-min.js
And on another rainy day, it would be nice to display the help strings for individual options :)
e.g.
./tool -h list
Option:
-l, --list Shows a list of items
Figured out my issue, I wasn't defining any commands.
Would be nice to have a really solid "cli tool" example which includes a few commands and options to help people get started faster. :)
If you ever have a rainy day and want to implement an 'array' type such that I could do -a foo -a bar
to produce [ "foo", "bar" ]
would be awesome.
It can improve quality of code.
I hit an issue while trying to pipe out to a text file. Our codebase is also using a spinner from the CLI library. I believe that I'm not in a position to share code, but here's the error dump I got:
vagrant@precise64:/vagrant/flh-etl$ node index > output.txt
/vagrant/flh-etl/modules/commandLineInterface/node_modules/cli/cli.js:1147
stream.clearLine();
^
TypeError: Object # has no method 'clearLine'
at null. (/vagrant/flh-etl/modules/commandLineInterface/node_modules/cli/cli.js:1147:16)
at wrapper as _onTimeout
at Timer.listOnTimeout as ontimeout
Hello,
In order to have properly read the package.json, when the cli app is installed globally I have to reference the package.json this way. better solutions appreciated.
var path = require('path');
var cli = require('cli');
var theFolder = path.dirname(require.main.filename);
var theFile = path.resolve(theFolder + '/../package.json');
cli.setApp(theFile);
Ciao
:m
Unfortunately the last commit messed things up for us. Since we're using an array of commands (and in JS typeof [] === 'object'
), it takes the keys of the array (0, 1, 2, 3) and makes them commands instead. Try using ! (commands instanceof Array)
instead.
https://github.com/chriso/cli/blob/master/cli.js#L263
https://github.com/chriso/cli/blob/master/cli.js#L665
I'd like to separate options in the --help
output.
Like a new line, or something similar to add more space.
Is there a way to do this or would it be possible to add this feature?
This issue came up in SublimeLinter/SublimeLinter-jshint#29 where the process terminates just before printing the version. Waiting for "drain" works for node 0.10+. Using node-exit might work for earlier versions.
What is the difference between this and tj/commander.js? Should the two projects be merged?
There really should be break's in these:
https://github.com/chriso/cli/blob/master/cli.js#L315-318
Hi,
Node (at least version 0.4.12 that I use right now) documents in its man page an environment variable NODE_DISABLE_COLORS.
Please respect that variable - both as alternative to no_color for the status module, and at other places where currently ANSI colors are hardcoded.
My specific need for this is in my packaging buddycloud-server officially for Debian where I want to autogenerate a man page from the output of --help option. Buddycloud-server uses node-hsconfig which in turn uses node-cli - which spew ANSI colors that messes up non-console capture of that --help output.
Hi, is it possible to add options per command? Something like:
Global options:
-a, --advanced Lets you specify your own oauth client id and secret on setup
-c, --config Set application path where config and token is stored.
-v, --version Print version
-h, --help Show this help
Verbs:
delete:
-i, --id File Id (*)
download:
-i, --id File Id (*)
-s, --stdout Write file content to stdout
Is there any subcommand support inside CLI ?
Like
$ my_cool_tool install foo bar
where foo
and bar
are arguments?
~/Sites/Beseda (beseda.io)$ git
usage: git [--version] [--exec-path[=<path>]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=<path>] [--work-tree=<path>]
[-c name=value] [--help]
<command> [<args>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
....
See 'git help <command>' for more information on a specific command.
when I call cli.setArgv and then cli.parse (lets say for unit tests) I noticed that each call to parse gets additive to the previous calls.
Right now I can put "cli.setArgv(); cli.options = {}" but it feels wrong to access the internals directly.
setArgv should reset options, or a new interface should be provided to do so.
We should exit the process with a return-code != 0 to let users and other scripts know that something is wrong.
Perhaps we can give cli.getUsage([code])
the return code or force it to 1
I set a option as 'string':
...
account: ['a', 'account number', 'string']
...
And this works well in most cases EXCEPT when the value is a number:
$ ./script.js -a 12345
In this case, typeof (options.account)
is number
. Can you do a covert to String when you do a cli.getValue(...)
?
Thanks!
Glob has changed it's interface starting with version 3.
I think the host typechecking is too strict as it checks for valid top level domains. Special hostnames that are often used internally are not accepted as domainnames.
ip-10-249-9-141.eu-west-1.compute.internal
foomachine
localhost
etc..
It should be enough to check that the hostname is either IP or otherwise valid hostname. Top level domain enforcing is not needed in my opinion.
On Windows with GitBash / GitShell there are line breaks after each progress message, which spams the terminal with unnecessary text :(
(even when using process.stderr.write()
)
That's because '\u000D'
is not processed correctly in the terminal (see in https://github.com/chriso/cli/blob/master/cli.js )
This works fine in Cygwin though.
Note that https://github.com/tj/node-progress works fine because it uses the process.stderr.clearLine/write/cursorTo()
API. See: https://github.com/tj/node-progress/blob/master/lib/node-progress.js#L140
My temporary fix:
var cli = require('cli');
//cli.native.util.print = console.log; (unnecessary line break)
cli.native.util.print = function(msg) { process.stderr.write(msg) };
To reproduce the bug:
https://github.com/chriso/cli/blob/master/examples/spinner.js
#!/usr/bin/env node
var cli = require('cli');
cli.spinner('Working..');
setTimeout(function () {
cli.spinner('Working.. done!', true); //End the spinner
}, 3000);
...outputs:
util.print: Use console.log instead
Working.. -util.print: Use console.log instead
Working.. \util.print: Use console.log instead
Working.. |util.print: Use console.log instead
Working.. /util.print: Use console.log instead
Working.. done!
https://github.com/chriso/cli/blob/master/examples/progress.js
#!/usr/bin/env node
var cli = require('cli');
var i = 0, interval = setInterval(function () {
cli.progress(++i / 100);
if (i === 100) {
clearInterval(interval);
cli.ok('Finished!');
}
}, 50);
...outputs:
util.print: Use console.log instead
[# ] 1%
util.print: Use console.log instead
[## ] 3%
util.print: Use console.log instead
[### ] 5%
util.print: Use console.log instead
[##### ] 7%
util.print: Use console.log instead
...
...
etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.