Skip to content

Commit ba14c93

Browse files
Saas 531 cli helm boards crud (#222)
1 parent 36c999d commit ba14c93

File tree

14 files changed

+692
-1
lines changed

14 files changed

+692
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const Command = require('../../Command');
2+
const { board: boardLogic } = require('../../../../logic').api;
3+
4+
const applyRoot = require('../root/apply.cmd');
5+
6+
const command = new Command({
7+
command: 'board [id]',
8+
aliases: [],
9+
parent: applyRoot,
10+
description: 'Update a board',
11+
webDocs: {
12+
category: 'Board',
13+
title: 'Update Board',
14+
},
15+
builder: (yargs) => {
16+
yargs
17+
.positional('id', {
18+
describe: 'Id of existing board',
19+
})
20+
.option('name', {
21+
describe: 'Name of existing board',
22+
})
23+
.option('newName', {
24+
describe: 'New name',
25+
})
26+
.option('filter', {
27+
describe: 'New filter',
28+
})
29+
.example(
30+
'codefresh patch board ID --new-name NEW_NAME --filter /app-*/gi',
31+
'Update name and filter of board. Specifying board by ID',
32+
)
33+
.example(
34+
'codefresh patch board --name OLD_NAME --new-name NEW_NAME --filter /app-*/gi',
35+
'Update name and filter of board. Specifying board by NAME',
36+
);
37+
38+
return yargs;
39+
},
40+
handler: async (argv) => {
41+
let { id } = argv;
42+
43+
const data = {
44+
name: argv.newName,
45+
filter: argv.filter,
46+
};
47+
48+
if (!id) {
49+
if (!argv.name) throw Error('Nor board-id nor board-name was specified');
50+
51+
const boardObj = await boardLogic.getBoardByName(argv.name);
52+
id = boardObj.id;
53+
}
54+
55+
56+
await boardLogic.updateBoard(id, data);
57+
console.log(`Board: "${data.name}" patched.`);
58+
},
59+
});
60+
61+
module.exports = command;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const Command = require('../../Command');
2+
const { board: boardLogic } = require('../../../../logic').api;
3+
const createRoot = require('../root/create.cmd');
4+
5+
const command = new Command({
6+
command: 'board <name>',
7+
parent: createRoot,
8+
description: 'Create a team',
9+
usage: 'You can create a board specifying name unique for account.',
10+
webDocs: {
11+
category: 'Boards',
12+
title: 'Create board',
13+
},
14+
builder: (yargs) => {
15+
return yargs
16+
.positional('name', {
17+
describe: 'Name of board',
18+
})
19+
.option('filter', {
20+
describe: 'Filter for clusters\' names',
21+
})
22+
.example('codefresh create board NAME', 'Creating a board')
23+
.example('codefresh create board NAME --filter /app-.*/gi', 'Creating a board with filter /app-.*/gi');
24+
},
25+
handler: async (argv) => {
26+
const reqBody = Object.assign({ name: argv.name }, argv.filter);
27+
28+
await boardLogic.createBoard(reqBody);
29+
console.log(`Board: "${reqBody.name}" created`);
30+
},
31+
});
32+
33+
module.exports = command;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const Command = require('../../Command');
2+
const { board } = require('../../../../logic').api;
3+
const deleteRoot = require('../root/delete.cmd');
4+
5+
const command = new Command({
6+
command: 'board [id]',
7+
aliases: [],
8+
parent: deleteRoot,
9+
description: 'Delete a board',
10+
webDocs: {
11+
category: 'Board',
12+
title: 'Delete board',
13+
},
14+
builder: (yargs) => {
15+
yargs
16+
.positional('id', {
17+
describe: 'board id',
18+
})
19+
.positional('name', {
20+
describe: 'board name',
21+
})
22+
.example('codefresh delete board --name NAME', 'Delete board by name.')
23+
.example('codefresh delete board ID', 'Delete board by Id.');
24+
return yargs;
25+
},
26+
handler: async (argv) => {
27+
const { name } = argv;
28+
let { id } = argv;
29+
30+
if (!id) {
31+
if (!name) throw Error('Nor board-id nor board-name was specified');
32+
33+
const boardObj = await board.getBoardByName(name);
34+
id = boardObj.id;
35+
}
36+
37+
await board.deleteBoard(id);
38+
console.log(`Board '${name || id}' deleted.`);
39+
},
40+
});
41+
42+
module.exports = command;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const debug = require('debug')('codefresh:cli:create:pipelines2');
2+
const Command = require('../../Command');
3+
const CFError = require('cf-errors');
4+
const { board: boardLogic } = require('../../../../logic').api;
5+
const { specifyOutputForArray } = require('../../helpers/get');
6+
7+
const getRoot = require('../root/get.cmd');
8+
9+
const command = new Command({
10+
command: 'boards [id..]',
11+
aliases: ['board'],
12+
parent: getRoot,
13+
description: 'Get a specific board or an array of boards',
14+
webDocs: {
15+
category: 'Boards',
16+
title: 'Get Board',
17+
},
18+
builder: (yargs) => {
19+
return yargs
20+
.option('id', {
21+
describe: 'Board by id',
22+
})
23+
.option('name', {
24+
describe: 'Board by name',
25+
});
26+
},
27+
handler: async (argv) => {
28+
const { id, name, output } = argv;
29+
if (id) {
30+
try {
31+
const board = await boardLogic.getBoardById(id);
32+
specifyOutputForArray(output, [board]);
33+
} catch (err) {
34+
debug(err.toString());
35+
const message = `Board '${id}' was not found`;
36+
throw new CFError({
37+
cause: err,
38+
message,
39+
});
40+
}
41+
} else if (name) {
42+
try {
43+
const board = await boardLogic.getBoardByName(name);
44+
specifyOutputForArray(output, [board]);
45+
} catch (err) {
46+
debug(err.toString());
47+
const message = `Board '${name}' was not found`;
48+
throw new CFError({
49+
cause: err,
50+
message,
51+
});
52+
}
53+
} else {
54+
specifyOutputForArray(output, await boardLogic.getAll({ name }));
55+
}
56+
},
57+
});
58+
59+
module.exports = command;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
const Command = require('../../Command');
2+
const _ = require('lodash');
3+
const { section: sectionLogic, board: boardLogic } = require('../../../../logic').api;
4+
5+
const applyRoot = require('../root/apply.cmd');
6+
7+
8+
const command = new Command({
9+
command: 'section [id]',
10+
aliases: [],
11+
parent: applyRoot,
12+
description: 'Update a section',
13+
webDocs: {
14+
category: 'Section',
15+
title: 'Update Section',
16+
},
17+
builder: (yargs) => {
18+
yargs
19+
.positional('id', {
20+
describe: 'Id of existing section',
21+
})
22+
.option('boardId', {
23+
describe: 'Id of existing board',
24+
})
25+
.option('boardName', {
26+
describe: 'Name of existing board',
27+
})
28+
.option('name', {
29+
describe: 'Name of existing section',
30+
})
31+
.option('newName', {
32+
describe: 'New name',
33+
})
34+
.option('cluster', {
35+
describe: 'Link to cluster',
36+
})
37+
.option('color', {
38+
describe: 'New color',
39+
})
40+
.option('index', {
41+
describe: 'New index',
42+
})
43+
.example(
44+
'codefresh patch section ID --new-name NEW_NAME --filter /app-*/gi',
45+
'Update name and filter of section. Specifying section by ID',
46+
)
47+
.example(
48+
'codefresh patch section --name OLD_NAME --new-name NEW_NAME --filter /app-*/gi',
49+
'Update name and filter of section. Specifying section by NAME',
50+
);
51+
52+
return yargs;
53+
},
54+
handler: async (argv) => {
55+
let { id, boardId } = argv;
56+
57+
if (!argv.boardId) {
58+
if (!argv.boardName) throw Error('Nor board-id nor board-name was specified');
59+
60+
const boardObj = await boardLogic.getBoardByName(argv.boardName);
61+
boardId = boardObj.id;
62+
}
63+
64+
const data = _.merge({}, {
65+
boardId,
66+
section: argv.cluster,
67+
color: argv.color,
68+
index: argv.index,
69+
name: argv.newName,
70+
});
71+
72+
if (!id) {
73+
if (!argv.name) throw Error('Nor section-id nor section-name was specified');
74+
75+
const sectionObj = await sectionLogic.getSectionByName({ boardId, name: argv.name });
76+
id = sectionObj.id;
77+
}
78+
79+
80+
await sectionLogic.updateSection(id, data);
81+
console.log(`Section: "${argv.name}" patched.`);
82+
},
83+
});
84+
85+
module.exports = command;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const Command = require('../../Command');
2+
const { section: sectionLogic, board: boardLogic } = require('../../../../logic').api;
3+
const createRoot = require('../root/create.cmd');
4+
5+
6+
const command = new Command({
7+
command: 'section <name>',
8+
parent: createRoot,
9+
description: 'Create a section',
10+
usage: 'You can create a section specifying name unique for account.',
11+
webDocs: {
12+
category: 'Sections',
13+
title: 'Create section',
14+
},
15+
builder: (yargs) => {
16+
return yargs
17+
.positional('name', {
18+
describe: 'Name of section',
19+
})
20+
.option('board-id', {
21+
describe: 'Id of board where section is creating',
22+
})
23+
.option('board-name', {
24+
describe: 'Name of board where section is creating',
25+
})
26+
.option('cluster', {
27+
describe: 'Name of linked cluster',
28+
})
29+
.option('color', {
30+
describe: 'Color of section',
31+
default: '#CCAA00',
32+
})
33+
.option('index', {
34+
describe: 'Index of section',
35+
default: '1',
36+
})
37+
.example(
38+
'codefresh create section NAME --board-name BOARD_NAME --cluster CLUSTER_NAME',
39+
'Creating a section with board name',
40+
)
41+
.example(
42+
'codefresh create section NAME --board-id ID --cluster CLUSTER_NAME --color "#00AACC" --index 1',
43+
'Creating a section with board id',
44+
);
45+
},
46+
handler: async (argv) => {
47+
const reqBody = {
48+
name: argv.name,
49+
boardId: argv.boardId,
50+
section: argv.cluster,
51+
color: argv.color,
52+
index: argv.index,
53+
};
54+
55+
if (!reqBody.boardId) {
56+
if (!argv.boardName) throw Error('Nor board-id nor board-name was specified');
57+
58+
const boardObj = await boardLogic.getBoardByName(argv.boardName);
59+
reqBody.boardId = boardObj.id;
60+
}
61+
62+
await sectionLogic.createSection(reqBody);
63+
console.log(`Section: "${reqBody.name}" created`);
64+
},
65+
});
66+
67+
68+
module.exports = command;

0 commit comments

Comments
 (0)