|
| 1 | +const debug = require('debug')('codefresh:cli:get:trigger-types'); |
| 2 | +const Command = require('../../../Command'); |
| 3 | +const _ = require('lodash'); |
| 4 | +const { trigger } = require('../../../../../logic').api; |
| 5 | +const { specifyOutputForSingle, specifyOutputForArray } = require('../../../helpers/get'); |
| 6 | +const getRoot = require('../../root/get.cmd'); |
| 7 | + |
| 8 | +const command = new Command({ |
| 9 | + command: 'trigger-types [type] [kind]', |
| 10 | + aliases: ['tt'], |
| 11 | + parent: getRoot, |
| 12 | + cliDocs: { |
| 13 | + description: 'Get a list of system-wide available `trigger-types` or specified `trigger-type`', |
| 14 | + }, |
| 15 | + webDocs: { |
| 16 | + category: 'Triggers', |
| 17 | + title: 'Get Trigger Types', |
| 18 | + }, |
| 19 | + builder: (yargs) => { |
| 20 | + return yargs |
| 21 | + .positional('type', { |
| 22 | + describe: '`trigger-type` type name (e.g. `registry`, `cron`)', |
| 23 | + }) |
| 24 | + .positional('kind', { |
| 25 | + describe: '`trigger-type` kind (e.g. `dockerhub`, `cfcr`, `gcr`, `acr`); only some `trigger-types` may have kinds', |
| 26 | + }); |
| 27 | + }, |
| 28 | + handler: async (argv) => { |
| 29 | + /* eslint-disable prefer-destructuring */ |
| 30 | + const type = argv.type; |
| 31 | + const kind = argv.kind; |
| 32 | + /* eslint-enable prefer-destructuring */ |
| 33 | + |
| 34 | + let types; |
| 35 | + if (type && kind) { |
| 36 | + types = await trigger.getType(type, kind); |
| 37 | + } else { |
| 38 | + types = await trigger.getAllTypes(); |
| 39 | + } |
| 40 | + |
| 41 | + if (_.isArray(types)) { |
| 42 | + specifyOutputForArray(argv.output, types); |
| 43 | + } else { |
| 44 | + specifyOutputForSingle(argv.output, types); |
| 45 | + } |
| 46 | + }, |
| 47 | +}); |
| 48 | + |
| 49 | +module.exports = command; |
| 50 | + |
0 commit comments