Skip to content

Commit 4f8d68e

Browse files
committed
Implement basic cli service
1 parent 2f4a996 commit 4f8d68e

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed

tools/office-cmdlet-updater/config/default.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"name": "Office cmdlet updater",
3+
"description": "Update documentation for modules in this repository",
4+
"version": "0.0.3",
25
"platyPS": {
36
"credentials": {
47
"login": "",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class CliController {
2+
constructor(cliService) {
3+
this.cliServoce = cliService;
4+
}
5+
6+
startCli(argv) {
7+
this.cliServoce.addOption({
8+
option: '-m --module <module>',
9+
description: 'update documentation for module',
10+
defaultValue: 'all'
11+
});
12+
13+
this.cliServoce.addOption({
14+
option: '-c --cmdlet <cmdet>',
15+
description: 'update documentation for cmdlet in module'
16+
});
17+
18+
this.cliServoce.start(argv, (cli) => {
19+
const { module, cmdlet } = cli;
20+
21+
console.log(module);
22+
console.log(cmdlet);
23+
});
24+
}
25+
}
26+
27+
module.exports = CliController;

tools/office-cmdlet-updater/helpers/di.container.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const MarkdownController = require('../controllers/markdown.controller');
99
const db = require('../db')();
1010
const CmdletDependenciesService = require('../services/cmdlet.dependencies.service');
1111
const FsService = require('../services/fs.service');
12+
const CliService = require('../services/cli.service');
13+
const CliController = require('../controllers/cli.controller');
1214

1315
module.exports = () => {
1416
const container = awilix.createContainer({
@@ -22,6 +24,7 @@ module.exports = () => {
2224
});
2325

2426
container.register({
27+
cliService: awilix.asClass(CliService).singleton(),
2528
mailNotificationService: awilix
2629
.asClass(MailNotificationService)
2730
.singleton(),
@@ -32,11 +35,12 @@ module.exports = () => {
3235
.asClass(CmdletDependenciesService)
3336
.singleton(),
3437
fsService: awilix.asClass(FsService).singleton(),
35-
markdownService: awilix.asClass(MarkdownService).singleton()
36-
});
38+
markdownService: awilix.asClass(MarkdownService).singleton()
39+
});
3740

3841
container.register({
39-
markdownController: awilix.asClass(MarkdownController).singleton()
42+
markdownController: awilix.asClass(MarkdownController).singleton(),
43+
cliController: awilix.asClass(CliController).singleton()
4044
});
4145

4246
return container;

tools/office-cmdlet-updater/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const container = require('./helpers/di.container')();
22

3-
(async function() {
4-
try {
5-
const markdownController = container.resolve('markdownController');
3+
try {
4+
const cliController = container.resolve('cliController');
65

7-
await markdownController.updateMarkdown();
8-
} catch (e) {
9-
console.log(e);
10-
}
11-
})();
6+
cliController.startCli(process.argv);
7+
} catch (e) {
8+
console.log(e);
9+
}

tools/office-cmdlet-updater/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"await-of": "^1.1.2",
2828
"awilix": "^3.0.9",
2929
"better-queue": "^3.8.10",
30+
"commander": "^2.19.0",
3031
"config": "^2.0.1",
3132
"fs-extra": "^7.0.0",
3233
"lowdb": "^1.0.0",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const cli = require('commander');
2+
3+
class CliService {
4+
constructor(config) {
5+
this.config = config;
6+
this.cli = cli;
7+
8+
const { description, version } = config;
9+
10+
this.cli.version(version, '-v, --version').description(description);
11+
}
12+
13+
addOption({
14+
option,
15+
description = '',
16+
defaultValue = '',
17+
action = () => {}
18+
}) {
19+
this.cli.option(option, description, defaultValue).action(action);
20+
}
21+
22+
start(argv, cb = () => {}) {
23+
this.cli.parse(argv);
24+
25+
cb(this.cli);
26+
}
27+
}
28+
29+
module.exports = CliService;

0 commit comments

Comments
 (0)