diff --git a/README.md b/README.md index c9b572e..3ae5af7 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ See the [GitHub API documentation for repositories](https://developer.github.com ## CLI ```sh -$ repos +$ repos [dest] ``` * `names` - one or more comma-separated user names or orgs -* `dest` - destination path to use, default is `repos.json` +* `dest` - destination path for JSON file (optional) ## About diff --git a/bin/cli.js b/bin/cli.js index d0cb4c9..851fa04 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -4,9 +4,16 @@ const repos = require('../'); const argv = require('minimist')(process.argv.slice(2)); const write = require('write'); +if (!argv.token && !(argv.username && argv.password)) { + argv.token = process.env.GITHUB_TOKEN; +} + repos(argv._[0].split(','), argv) .then(res => { - let filepath = argv._[1] || 'repos.json'; + let filepath = argv._[1]; + if (!filepath) { + return console.log(JSON.stringify(res, null, 2)); + } write(filepath, JSON.stringify(res, null, 2), err => { if (err) { console.error(err); diff --git a/test/support/auth.js b/test/support/auth.js index 64658e4..3f19113 100644 --- a/test/support/auth.js +++ b/test/support/auth.js @@ -14,6 +14,9 @@ if (!auth) { } else { auth.username = argv.username || argv._[0] || process.env.GITHUB_USERNAME; auth.password = argv.password || argv._[1] || process.env.GITHUB_PASSWORD; + if (!auth.username || !auth.password) { + auth.token = process.env.GITHUB_TOKEN; + } } }