Skip to content

Commit

Permalink
Add API option and set default url to the v2 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor committed Sep 19, 2016
1 parent 36a1297 commit 46800cf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/info.js
Expand Up @@ -18,10 +18,14 @@ exports.builder = (yargs) =>
describe: 'Format the results in a human readable format or as JSON',
default: 'human',
},
api: {
describe: 'The API url',
default: 'https://api.npms.io/v2',
},
});

exports.handler = (argv) => {
got(`https://api.npms.io/package/${encodeURIComponent(argv.package)}`, { json: true })
got(`${argv.api}/package/${encodeURIComponent(argv.package)}`, { json: true })
.then((res) => {
if (argv.output === 'json') {
console.log(JSON.stringify(res.body, null, 2));
Expand Down
6 changes: 5 additions & 1 deletion cmd/open.js
Expand Up @@ -40,10 +40,14 @@ exports.builder = (yargs) =>
type: 'string',
default: 'auto',
},
api: {
describe: 'The API url',
default: 'https://api.npms.io/v2',
},
});

exports.handler = (argv) => {
got(`https://api.npms.io/package/${encodeURIComponent(argv.package)}`, { json: true })
got(`${argv.api}/package/${encodeURIComponent(argv.package)}`, { json: true })
.then((res) => getLink(argv, res))
.then((link) => opn(link, { wait: false }))
.then(() => { process.exitCode = 0; })
Expand Down
6 changes: 5 additions & 1 deletion cmd/search.js
Expand Up @@ -35,10 +35,14 @@ exports.builder = (yargs) =>
describe: 'Format the results in a table or as JSON',
default: 'table',
},
api: {
describe: 'The API url',
default: 'https://api.npms.io/v2',
},
});

exports.handler = (argv) => {
got('https://api.npms.io/search', {
got(`${argv.api}/search`, {
json: true,
query: JSON.parse(JSON.stringify({
q: argv.query.join(' '),
Expand Down
4 changes: 4 additions & 0 deletions test/util/exec.js
Expand Up @@ -70,6 +70,10 @@ function waitForExit(timeout) {
function exec(argv, options) {
options = Object.assign({ printStderr: true, timeout: 1500 }, options);

// Force api url without version
argv.push('--api');
argv.push('https://api.npms.io');

// Clear the cli & yargs from the module cache
delete require.cache[require.resolve('../../cli')];
delete require.cache[require.resolve('yargs')];
Expand Down

0 comments on commit 46800cf

Please sign in to comment.