|
1 | 1 | #!/usr/bin/env node |
2 | 2 |
|
3 | | -const path = require('path'); |
4 | | -const _ = require('lodash'); |
5 | | -const yargs = require('yargs'); |
6 | | -const recursive = require('recursive-readdir'); |
7 | | -const CFError = require('cf-errors'); |
8 | | -const DEFAULTS = require('./defaults'); |
9 | | -const authManager = require('../../logic').auth.manager; |
10 | 3 | const { printError } = require('./helpers/general'); |
11 | 4 |
|
12 | | -process.on('uncaughtException', function (err) { |
| 5 | +process.on('uncaughtException', (err) => { |
13 | 6 | printError(err); |
14 | 7 | process.exit(1); |
15 | 8 | }); |
16 | 9 |
|
17 | | -process.on('unhandledRejection', error => { |
18 | | - printError(error); |
| 10 | +process.on('unhandledRejection', (err) => { |
| 11 | + printError(err); |
19 | 12 | process.exit(1); |
20 | 13 | }); |
21 | 14 |
|
| 15 | +if (process.argv.includes('--get-yargs-completions')) { |
| 16 | + const initCompletion = require('./completion'); |
| 17 | + initCompletion().argv; |
| 18 | +} else { |
| 19 | + const _ = require('lodash'); |
| 20 | + const yargs = require('yargs'); |
| 21 | + const path = require('path'); |
| 22 | + const recursive = require('recursive-readdir'); |
| 23 | + const DEFAULTS = require('./defaults'); |
| 24 | + const authManager = require('../../logic').auth.manager; |
22 | 25 |
|
23 | | -recursive(path.resolve(__dirname, 'commands'), (err, files) => { |
24 | | - const rootCommands = []; |
25 | | - yargs |
26 | | - .env('') |
27 | | - .options('cfconfig', { |
28 | | - default: DEFAULTS.CFCONFIG, |
29 | | - global: false, |
30 | | - }) |
31 | | - .config('cfconfig', 'Custom path for authentication contexts config file', (configFilePath) => { |
32 | | - try { |
33 | | - authManager.loadContexts(process.env.CF_API_KEY, process.env.CF_URL || DEFAULTS.URL , configFilePath); |
34 | | - _.forEach(files, (file) => { |
35 | | - if (file.endsWith('.cmd.js')) { |
36 | | - const command = require(file); |
37 | | - if (command.isRoot()) { |
38 | | - if (command.isBetaCommand()) { |
39 | | - const currentContext = authManager.getCurrentContext(); |
40 | | - if (currentContext && currentContext.isBetaFeatEnabled()) { |
| 26 | + recursive(path.resolve(__dirname, 'commands'), (err, files) => { |
| 27 | + const rootCommands = []; |
| 28 | + yargs |
| 29 | + .env('') |
| 30 | + .options('cfconfig', { |
| 31 | + default: DEFAULTS.CFCONFIG, |
| 32 | + global: false, |
| 33 | + }) |
| 34 | + .config('cfconfig', 'Custom path for authentication contexts config file', (configFilePath) => { |
| 35 | + try { |
| 36 | + authManager.loadContexts(process.env.CF_API_KEY, process.env.CF_URL || DEFAULTS.URL, configFilePath); |
| 37 | + _.forEach(files, (file) => { |
| 38 | + if (file.endsWith('.cmd.js')) { |
| 39 | + const command = require(file); |
| 40 | + if (command.isRoot()) { |
| 41 | + if (command.isBetaCommand()) { |
| 42 | + const currentContext = authManager.getCurrentContext(); |
| 43 | + if (currentContext && currentContext.isBetaFeatEnabled()) { |
| 44 | + rootCommands.push(command); |
| 45 | + } |
| 46 | + } else { |
41 | 47 | rootCommands.push(command); |
42 | 48 | } |
43 | | - } else { |
44 | | - rootCommands.push(command); |
45 | 49 | } |
46 | 50 | } |
47 | | - } |
48 | | - }); |
49 | | - _.forEach(rootCommands, (command) => { |
50 | | - yargs.command(command.toCommand()); |
51 | | - }); |
52 | | - } catch (err) { |
53 | | - printError(err); |
54 | | - process.exit(1); |
55 | | - } |
56 | | - }); |
| 51 | + }); |
| 52 | + _.forEach(rootCommands, (command) => { |
| 53 | + yargs.command(command.toCommand()); |
| 54 | + }); |
| 55 | + } catch (err) { |
| 56 | + printError(err); |
| 57 | + process.exit(1); |
| 58 | + } |
| 59 | + }); |
57 | 60 |
|
58 | 61 |
|
59 | | - yargs // eslint-disable-line |
60 | | - .completion() |
61 | | - .demandCommand(1, 'You need at least one command before moving on') |
62 | | - .wrap(null) |
63 | | - .version(false) |
64 | | - .help('help') |
65 | | - .epilogue('For more information, find our official documentation at http://cli.codefresh.io') |
66 | | - // .option('help', { |
67 | | - // global: false, |
68 | | - // }) |
69 | | - .argv; |
70 | | -}); |
| 62 | + yargs // eslint-disable-line |
| 63 | + .demandCommand(1, 'You need at least one command before moving on') |
| 64 | + .wrap(null) |
| 65 | + .version(false) |
| 66 | + .help('help') |
| 67 | + .epilogue('For more information, find our official documentation at http://cli.codefresh.io') |
| 68 | + // .option('help', { |
| 69 | + // global: false, |
| 70 | + // }) |
| 71 | + .argv; |
| 72 | + }); |
| 73 | +} |
| 74 | + |
0 commit comments