Giter Club home page Giter Club logo

cli's People

Contributors

agnoster avatar andreastt avatar bbosman avatar btecu avatar chriso avatar cri5ti avatar freiksenet avatar jacksontian avatar jamesgpearce avatar jugglinmike avatar kainosnoema avatar kodeandgame avatar mimetnet avatar olegas avatar pdehaan avatar robertderose avatar shumkov avatar tikonen avatar touchesir avatar ultcombo avatar zackurben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cli's Issues

Please include a license

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!

'host' option typechecking too strict

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.

Help on individual options

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

refine boolean options parsing

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".

URL not allowing all URLs

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...

Clarify option type in docs

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.

Spinner/progress, terminal line breaking in Windows (GitBash / Shell), Cygwin okay

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

Default value of number 0 doesn't get output in help

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

possibility to set arguments

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.

daemon plugin seems to be broken...

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:

  • Node 0.4.2
  • daemon 0.3.0
  • cli 0.2.7

cli --version

$ 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?

Nested commands

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>

Spinner/progress, Node v0.12 deprecated util.print "Use console.log instead"

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.

Please respect NODE_DISABLE_COLORS

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.

cli.setApp('package.json') installed globally

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

array support

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.

log read fails with process out of memory

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?

Help doesn't work

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. :)

'string' value_type for options not converted when number is passed

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!

Help padding bug

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

Error if commands not present

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)
    ....

glob dep is too loose

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 :)

Provide a way to suppress param data type being output on --help

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.

cli.options does not get reset when setArgv gets called

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.

Piping conflicts with spinner

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

Options & Commands

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
});

Print help if commands not present

~/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.

can't use -k and --debug together

-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

Options with no short name

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.

per command options

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

cli.getUsage([code])

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

Update to latest version of `glob`

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

Subcommand support

Is there any subcommand support inside CLI ?

Like

$ my_cool_tool install foo bar

where foo and bar are arguments?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.