Skip to content

Commit

Permalink
Merge pull request #139 from codefresh-io/triggers_commands
Browse files Browse the repository at this point in the history
update cli to work with trigger-events
  • Loading branch information
alexei-led authored Feb 11, 2018
2 parents 7407173 + ca3a74a commit 8393f5b
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 101 deletions.
40 changes: 0 additions & 40 deletions lib/interface/cli/commands/trigger/delete.cmd.js

This file was deleted.

47 changes: 47 additions & 0 deletions lib/interface/cli/commands/trigger/event/create.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require('debug')('codefresh:cli:create:trigger-event');

const Command = require('../../../Command');
const { trigger } = require('../../../../../logic').api;
const { prepareKeyValueFromCLIEnvOption } = require('../../../helpers/general');
const createRoot = require('../../root/create.cmd');

const command = new Command({
command: 'trigger-event',
parent: createRoot,
description: 'Create new `trigger-event`',
webDocs: {
category: 'Triggers',
title: 'Create Trigger Event',
},
builder: (yargs) => {
yargs
.option('type', {
describe: 'trigger-event type',
require: true,
})
.option('kind', {
describe: 'trigger-event kind',
})
.option('secret', {
describe: 'trigger-event secret (omit to auto-generate)',
require: true,
default: '!generate',
})
.option('value', {
describe: 'trigger-event specific values pairs (key=value), as required by trigger-type',
default: [],
})
.option('context', {
describe: 'context with credentials required to setup event on remote system',
})
.example('codefresh create trigger-event --type registry --kind dockerhub --secret XYZ1234 --value namespace=codefresh --value name=fortune --context dockerhub', 'Create registry/dockerhub trigger-event');
},
handler: async (argv) => {
const values = prepareKeyValueFromCLIEnvOption(argv.value);
const event = await trigger.createEvent(argv.type, argv.kind, argv.secret, values, argv.context);
console.log(`Trigger event: ${event.uri} was successfully created.`);
},
});

module.exports = command;

32 changes: 32 additions & 0 deletions lib/interface/cli/commands/trigger/event/delete.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require('debug')('codefresh:cli:delete:trigger-event');

const Command = require('../../../Command');
const { trigger } = require('../../../../../logic').api;
const deleteRoot = require('../../root/delete.cmd');

const command = new Command({
command: 'trigger-event [event-uri]',
parent: deleteRoot,
description: 'Delete `trigger-event`',
webDocs: {
category: 'Triggers',
title: 'Delete Trigger Event',
},
builder: (yargs) => {
yargs
.positional('event-uri', {
describe: 'trigger-event URI',
})
.option('context', {
describe: 'context with credentials required to setup event on remote system',
})
.example('codefresh delete trigger-event --context dockerhub registry:dockerhub:codefresh:fortune:push', 'Delete registry/dockerhub trigger-event');
},
handler: async (argv) => {
await trigger.deleteEvent(argv['event-uri'], argv.context);
console.log(`Trigger event: ${argv['event-uri']} was successfully deleted.`);
},
});

module.exports = command;

25 changes: 11 additions & 14 deletions lib/interface/cli/commands/trigger/event/get.cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const debug = require('debug')('codefresh:cli:get:trigger-event');
require('debug')('codefresh:cli:get:trigger-event');

const Command = require('../../../Command');
const _ = require('lodash');
const { trigger } = require('../../../../../logic').api;
Expand All @@ -7,31 +8,27 @@ const getRoot = require('../../root/get.cmd');

const command = new Command({
command: 'trigger-event <event-uri>',
aliases: ['te', 'event'],
parent: getRoot,
description: 'Get detailed information about specified `trigger-event`',
description: 'Get `trigger-event`',
webDocs: {
category: 'Triggers',
title: 'Get Trigger Event',
},
builder: (yargs) => {
return yargs
yargs
.positional('event-uri', {
describe: '`trigger-event` uri (as defined by trigger `type[/kind]`)',
describe: '`trigger-event` URI (as defined by trigger `type[/kind]`)',
require: true,
});
})
.example('codefresh get trigger-event registry:dockerhub:codefresh:fortune:push', 'Get DockerHub codefresh/fortune push `trigger-event`');
},
handler: async (argv) => {
/* eslint-disable prefer-destructuring */
const eventURI = argv['event-uri'];
/* eslint-enable prefer-destructuring */

const info = await trigger.getEventInfo(eventURI);
const event = await trigger.getEvent(argv['event-uri']);

if (_.isArray(info)) {
specifyOutputForArray(argv.output, info);
if (_.isArray(event)) {
specifyOutputForArray(argv.output, event);
} else {
specifyOutputForSingle(argv.output, info);
specifyOutputForSingle(argv.output, event);
}
},
});
Expand Down
4 changes: 2 additions & 2 deletions lib/interface/cli/commands/trigger/get.cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const debug = require('debug')('codefresh:cli:get:triggers');
require('debug')('codefresh:cli:get:triggers');
const Command = require('../../Command');
const _ = require('lodash');
const { trigger } = require('../../../../logic').api;
Expand All @@ -15,7 +15,7 @@ const command = new Command({
title: 'Get Pipeline Triggers',
},
builder: (yargs) => {
return yargs
yargs
.positional('pipeline', {
describe: 'pipeline id',
require: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
const debug = require('debug')('codefresh:cli:create:trigger');
require('debug')('codefresh:cli:create:trigger');

const Command = require('../../Command');
const { trigger } = require('../../../../logic').api;
const createRoot = require('../root/create.cmd');

const command = new Command({
command: 'trigger <event-uri> <pipeline> [pipelines...]',
aliases: ['t'],
parent: createRoot,
description: 'Set pipeline(s) trigger: connect the `trigger-event` to the pipeline(s). *Note:* `trigger-event` exists only if there is at least one connected pipeline.',
root: true,
command: 'link <event-uri> <pipeline> [pipelines...]',
description: 'Define new trigger(s): link pipeline(s) to the specified `trigger-event`',
webDocs: {
category: 'Triggers',
title: 'Set Pipeline Trigger',
title: 'Define Pipeline Trigger',
},
builder: (yargs) => {
return yargs
yargs
.positional('event-uri', {
describe: '`trigger-event` URI (as defined by trigger `type[/kind]`)',
require: true,
})
.positional('pipeline', {
describe: 'pipeline(s) to be triggered by the specified `trigger-event`',
require: true,
});
})
.example('codefresh link registry:dockerhub:codefresh:fortune:push 5a439664af73ad0001f3ece0', 'Setup trigger by linking 5a43... pipeline to the DockerHub `codefresh/fortune` `push` event');
},
handler: async (argv) => {
/* eslint-disable prefer-destructuring */
const pipelines = [].concat(argv.pipeline).concat(argv.pipelines);
const eventURI = argv['event-uri'];
const event = argv['event-uri'];
/* eslint-enable prefer-destructuring */
await trigger.addPipelineTrigger(eventURI, pipelines);
console.log(`Trigger : ${eventURI} was successfully added to the pipeline(s): ${pipelines}`);
await trigger.linkPipelinesToEvent(event, pipelines);
console.log(`Trigger: ${event} was successfully linked to the pipeline(s): ${pipelines}`);
},
});

Expand Down
9 changes: 5 additions & 4 deletions lib/interface/cli/commands/trigger/type/get.cmd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const debug = require('debug')('codefresh:cli:get:trigger-types');
require('debug')('codefresh:cli:get:trigger-types');

const Command = require('../../../Command');
const _ = require('lodash');
const { trigger } = require('../../../../../logic').api;
Expand All @@ -7,21 +8,21 @@ const getRoot = require('../../root/get.cmd');

const command = new Command({
command: 'trigger-types [type] [kind]',
aliases: ['tt'],
parent: getRoot,
description: 'Get a list of system-wide available `trigger-types` or specified `trigger-type`',
webDocs: {
category: 'Triggers',
title: 'Get Trigger Types',
},
builder: (yargs) => {
return yargs
yargs
.positional('type', {
describe: '`trigger-type` type name (e.g. `registry`, `cron`)',
})
.positional('kind', {
describe: '`trigger-type` kind (e.g. `dockerhub`, `cfcr`, `gcr`, `acr`); only some `trigger-types` may have kinds',
});
})
.example('codefresh get trigger-types --type registry', 'Get Docker registry trigger types');
},
handler: async (argv) => {
/* eslint-disable prefer-destructuring */
Expand Down
38 changes: 38 additions & 0 deletions lib/interface/cli/commands/trigger/unlink.cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require('debug')('codefresh:cli:delete:trigger');

const Command = require('../../Command');
const { trigger } = require('../../../../logic').api;

const command = new Command({
root: true,
command: 'unlink <event-uri> <pipeline> [pipelines...]',
description: 'Undefine trigger(s): unlink pipeline(s) from the specified `trigger-event`',
webDocs: {
category: 'Triggers',
title: 'Remove Pipeline Trigger',
},
builder: (yargs) => {
yargs
.positional('event-uri', {
describe: '`trigger-event` URI (as defined by trigger `type[/kind]`)',
required: true,
})
.positional('pipeline', {
describe: 'pipeline ID',
required: true,
})
.example('codefresh unlink registry:dockerhub:codefresh:fortune:push 5a439664af73ad0001f3ece0', 'Remove trigger by unlinking 5a43... pipeline from the DockerHub `codefresh/fortune` `push` event');
},
handler: async (argv) => {
/* eslint-disable prefer-destructuring */
const event = argv['event-uri'];
const pipelines = [].concat(argv.pipeline).concat(argv.pipelines);
/* eslint-enable prefer-destructuring */

await trigger.unlinkPipelinesFromEvent(event, pipelines);
console.log(`Trigger: ${eventURI} was unlinked from the pipeline(s): ${pipelines}`);
},
});

module.exports = command;

Loading

0 comments on commit 8393f5b

Please sign in to comment.