Skip to content

Commit 2c6932a

Browse files
Refactor CLI interface structure (#40)
1 parent 6faeac2 commit 2c6932a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+2220
-1873
lines changed

examples/cfconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
contexts:
2+
testcontext1:
3+
type: JWT
4+
name: testcontext1
5+
url: 'https://g.codefresh.io'
6+
token: >-
7+
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJfaWQiOiI1NTJlOTQyMjM4MjQ4MzFkMDBiMWNhM2UiLCJhY2NvdW50SWQiOiI1NjgwZjEzMDM0Y2RiMzE3N2M4MmFjYjIiLCJpYXQiOjE1MTIyMzA5MDcsImV4cCI6MTUxNDgyMjkwN30.-OUq7kVLVghCjV4tp7swSzCyzPn-GR3ZF0A-aZo1ic0
8+
acl-type: account
9+
user-id: 552e94223824831d00b1ca3e
10+
account-id: 5680f13034cdb3177c82acb2
11+
expires: 1514822907
12+
user-name: verchol
13+
account-name: verchol_github
14+
current-context: testcontext1

lib/interface/cli/Command.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const yargs = require('yargs');
2+
const assert = require('assert');
3+
const _ = require('lodash');
4+
const { wrapHandler } = require('./helpers/general');
5+
6+
class Command {
7+
constructor(command) {
8+
this.command = command;
9+
this.subCommands = [];
10+
this.builders = [];
11+
(_.isUndefined(command.handler)) ? command.handler = (args) => {
12+
console.log(`i am ${command.description}`);
13+
14+
} : _.noop();
15+
(_.isUndefined(command.builder)) ? _.noop() :
16+
this.addBuilder(command.builder);
17+
18+
}
19+
20+
addBuilder(b) {
21+
this.builders.push(b);
22+
}
23+
24+
subCommand(command) {
25+
this.subCommands.push(command);
26+
return this;
27+
}
28+
29+
toCommand() {
30+
let command = this.command;
31+
//assert(_.get(this.command, "builder", true));
32+
33+
let funcs = _.map(this.builders, (b) => {
34+
return (yargs) => {
35+
b(yargs);
36+
_.forEach(this.subCommands, (subCommand) => {
37+
// TODO use .toCommand here too
38+
if (subCommand instanceof Command) {
39+
yargs.command(subCommand.toCommand());
40+
} else {
41+
yargs.command(subCommand);
42+
}
43+
});
44+
return yargs;
45+
};
46+
});
47+
48+
let builder = (yargs) => {
49+
_.flow(funcs)(yargs);
50+
};
51+
52+
command.builder = builder;
53+
command.handler = wrapHandler(command.handler);
54+
return command;
55+
56+
}
57+
58+
}
59+
60+
61+
module.exports = Command;

lib/interface/cli/commands/annotate/commands/image.js

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

lib/interface/cli/commands/annotate/commands/index.js

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

lib/interface/cli/commands/annotate/index.js

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

lib/interface/cli/commands/apply/commands/context.js

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

lib/interface/cli/commands/apply/commands/index.js

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

lib/interface/cli/commands/apply/commands/pipeline.js

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

lib/interface/cli/commands/apply/index.js

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

0 commit comments

Comments
 (0)