Skip to content

Commit 36ca860

Browse files
Auto load all commands (#43)
1 parent a4d3d35 commit 36ca860

Some content is hidden

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

48 files changed

+156
-147
lines changed

lib/interface/cli/Command.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
const yargs = require('yargs');
22
const assert = require('assert');
33
const _ = require('lodash');
4-
const { wrapHandler } = require('./helpers/general');
4+
const { printError, wrapHandler } = require('./helpers/general');
5+
56

67
class Command {
78
constructor(command) {
9+
this.root = command.root;
10+
delete command.root;
11+
812
this.command = command;
913
this.subCommands = [];
1014
this.builders = [];
1115
(_.isUndefined(command.handler)) ? command.handler = (args) => {
12-
console.log(`i am ${command.description}`);
16+
printError(`Error: unknown command "${args._[args._.length - 1]}"\n` +
17+
'Run \'codefresh --help\' for usage.');
1318

1419
} : _.noop();
1520
(_.isUndefined(command.builder)) ? _.noop() :
1621
this.addBuilder(command.builder);
1722

1823
}
1924

25+
isRoot() {
26+
return this.root;
27+
}
28+
2029
addBuilder(b) {
2130
this.builders.push(b);
2231
}

lib/interface/cli/commands/auth/create-context.js renamed to lib/interface/cli/commands/auth/create-context.cmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DEFAULTS = require('../../defaults');
66
const { auth } = require('../../../../logic');
77
const { JWTContext } = auth.contexts;
88
const authManager = auth.manager;
9+
const authRoot = require('../root/auth.cmd');
910

1011
const _loginWithToken = async (url, token) => {
1112
try {
@@ -71,5 +72,6 @@ const command = new Command({
7172
console.log(`Switched to context: ${authContext.name}`);
7273
},
7374
});
75+
authRoot.subCommand(command);
7476

7577
module.exports = command;

lib/interface/cli/commands/auth/current-context.js renamed to lib/interface/cli/commands/auth/current-context.cmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const { auth } = require('../../../../logic');
55
const authManager = auth.manager;
6+
const authRoot = require('../root/auth.cmd');
67

78

89
const command = new Command({
@@ -20,5 +21,6 @@ const command = new Command({
2021
}
2122
},
2223
});
24+
authRoot.subCommand(command);
2325

2426
module.exports = command;

lib/interface/cli/commands/auth/get-contexts.js renamed to lib/interface/cli/commands/auth/get-contexts.cmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const debug = require('debug')('codefresh:auth:get-contexts');
22
const Command = require('../../Command');
33
const _ = require('lodash');
44
const { printTableForAuthContexts } = require('../../helpers/auth');
5+
const authRoot = require('../root/auth.cmd');
56

67
const command = new Command({
78
command: 'get-contexts',
@@ -13,5 +14,7 @@ const command = new Command({
1314
printTableForAuthContexts();
1415
},
1516
});
17+
authRoot.subCommand(command);
18+
1619

1720
module.exports = command;

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

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

lib/interface/cli/commands/auth/login.js renamed to lib/interface/cli/commands/auth/login.cmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DEFAULTS = require('../../defaults');
66
const { auth } = require('../../../../logic');
77
const { JWTContext } = auth.contexts;
88
const authManager = auth.manager;
9+
const authRoot = require('../root/auth.cmd');
910

1011
const _loginWithUserPassword = async (username, password) => {
1112
try {
@@ -49,6 +50,7 @@ const command = new Command({
4950
console.log(`Switched to context: ${authContext.name}`);
5051
},
5152
});
53+
authRoot.subCommand(command);
5254

5355

5456
module.exports = command;

lib/interface/cli/commands/auth/use-context.js renamed to lib/interface/cli/commands/auth/use-context.cmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const CFError = require('cf-errors');
44
const _ = require('lodash');
55
const { auth } = require('../../../../logic');
66
const authManager = auth.manager;
7+
const authRoot = require('../root/auth.cmd');
78

89

910
const command = new Command({
@@ -29,5 +30,7 @@ const command = new Command({
2930
}
3031
},
3132
});
33+
authRoot.subCommand(command);
34+
3235

3336
module.exports = command;

lib/interface/cli/commands/composition/create.js renamed to lib/interface/cli/commands/composition/create.cmd.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const _ = require('lodash');
55
const { prepareKeyValueCompostionFromCLIEnvOption, printError } = require('../../helpers/general');
66
const { composition } = require('../../../../logic').api;
77
const fs = require('fs');
8+
const createRoot = require('../root/create.cmd');
89

910

1011
const command = new Command({
@@ -53,6 +54,7 @@ const command = new Command({
5354
console.log(`Composition: ${data.name} created`);
5455
},
5556
});
57+
createRoot.subCommand(command);
5658

5759

5860
module.exports = command;

lib/interface/cli/commands/composition/delete.js renamed to lib/interface/cli/commands/composition/delete.cmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
55
const { composition } = require('../../../../logic').api;
6+
const deleteRoot = require('../root/delete.cmd');
67

78

89
const command = new Command({
@@ -25,6 +26,8 @@ const command = new Command({
2526
console.log(`Composition: ${name} deleted`);
2627
},
2728
});
29+
deleteRoot.subCommand(command);
30+
2831

2932
module.exports = command;
3033

lib/interface/cli/commands/composition/describe.js renamed to lib/interface/cli/commands/composition/describe.cmd.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Command = require('../../Command');
33
const CFError = require('cf-errors');
44
const _ = require('lodash');
55
const { composition } = require('../../../../logic').api;
6+
const describeRoot = require('../root/describe.cmd');
67

78

89
const command = new Command({
@@ -21,6 +22,8 @@ const command = new Command({
2122
console.log(currComposition.describe());
2223
},
2324
});
25+
describeRoot.subCommand(command);
26+
2427

2528
module.exports = command;
2629

0 commit comments

Comments
 (0)