Skip to content

Commit d6e0cec

Browse files
author
Dom Harrington
committed
Rename a few things
1 parent 810c7ee commit d6e0cec

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

api.js renamed to cli.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@ const path = require('path');
44

55
const utils = require('./utils');
66

7-
exports.api = function(args, opts = {}) {
8-
const action = args[0];
9-
const config = utils.config(opts.env);
10-
11-
const actionObj = exports.load(config, action);
12-
13-
if (!actionObj) {
14-
return;
15-
}
16-
17-
const info = {
18-
args,
19-
opts,
20-
};
21-
22-
actionObj.run(config, info);
23-
};
24-
25-
exports.load = function(config, action = 'help') {
26-
const file = path.join(__dirname, 'lib', `${action}.js`);
7+
function load(config, command = 'help') {
8+
const file = path.join(__dirname, 'lib', `${command}.js`);
279
try {
2810
// eslint-disable-next-line global-require, import/no-dynamic-require
2911
return require(file);
3012
} catch (e) {
31-
console.error('Action not found.'.red);
13+
console.error('Command not found.'.red);
3214
console.warn(`Type ${`${config.cli} help`.yellow} to see all commands`);
3315
process.exitCode = 1;
3416
return undefined;
3517
}
3618
};
19+
20+
module.exports = function(args, opts = {}) {
21+
const config = utils.config(opts.env);
22+
23+
const command = load(config, args[0]);
24+
25+
if (!command) return;
26+
27+
command.run(config, { args, opts });
28+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "rdme",
44
"description": "ReadMe's API CLI",
55
"bin": {
6-
"rdme": "index.js"
6+
"rdme": "rdme.js"
77
},
88
"tags": [
99
"api",

index.js renamed to rdme.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#! /usr/bin/env node
22
const parseArgs = require('minimist')(process.argv.slice(2));
33

4-
require('./api').api(parseArgs._, parseArgs);
4+
require('./cli')(parseArgs._, parseArgs);

test/api.test.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/cli.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const assert = require('assert');
2+
3+
const cli = require('../cli');
4+
5+
describe('cli', () => {
6+
let error;
7+
beforeAll(() => {
8+
error = { console };
9+
});
10+
11+
afterAll(() => {
12+
console.error = error;
13+
});
14+
15+
it('command not found', done => {
16+
console.error = message => {
17+
assert(message.includes('Command not found'));
18+
return done();
19+
};
20+
cli('notARealCommand');
21+
});
22+
});

0 commit comments

Comments
 (0)