Skip to content

Commit 5a9b3d4

Browse files
new tag/untag operations (#430)
* new tag/untag operations * fix tests * fix messages * fix typi * error processing * update version Co-authored-by: Itai Gendler <itai@codefresh.io>
1 parent 0b34605 commit 5a9b3d4

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

lib/interface/cli/commands/image/image.sdk.spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ describe('image commands', () => {
7272
it('should handle tagging', async () => {
7373
const argv = { id: 'some id', tags: ['tag'] };
7474
const responses = [
75-
{ statusCode: 200, body: { _id: 'some id' } },
7675
DEFAULT_RESPONSE,
7776
];
7877
request.__queueResponses(responses);
@@ -85,7 +84,6 @@ describe('image commands', () => {
8584
it('should handle removing tags', async () => {
8685
const argv = { id: 'some id', tags: ['tag'] };
8786
const responses = [
88-
{ statusCode: 200, body: { _id: 'some id', tags: [{ _id: 'tag id', tag: 'tag' }] } },
8987
DEFAULT_RESPONSE,
9088
];
9189
request.__queueResponses(responses);

lib/interface/cli/commands/image/tag.cmd.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const tag = new Command({
88
command: 'tag <id> [tags..]',
99
category: 'Images',
1010
description: 'Add an image tag',
11-
usage: 'Tagging an image will result in the creation of a new Docker Image tag',
11+
usage: 'Tagging an image will result in the creation of a new Docker Image tag. If registry not specified - default is used',
1212
webDocs: {
1313
category: 'Images',
1414
title: 'Tag Image',
@@ -25,21 +25,24 @@ const tag = new Command({
2525
.positional('names', {
2626
description: 'Tag names',
2727
})
28-
.example('codefresh tag 2dfacdaad466 1.0.0', "Tag image '2dfacdaad466' with a new tag: '1.0.0'")
28+
.option('registry', {
29+
alias: 'r',
30+
description: 'Registry integration name',
31+
})
32+
.example('codefresh tag 2dfacdaad466 1.0.0', "Tag image '2dfacdaad466' with a new tag: '1.0.0' on default registry")
33+
.example('codefresh tag 2dfacdaad466 1.0.0 --registry dockerhub', "Tag image '2dfacdaad466' with a new tag: '1.0.0' on dockerhub")
2934
.example('codefresh tag 2dfacdaad466 1.0.0 my-tag', "Tag image '2dfacdaad466' with multiple tags: '1.0.0' and 'my-tag'");
3035

3136
return yargs;
3237
},
3338
handler: async (argv) => {
34-
let id = argv.id;
39+
const id = argv.id;
3540
const tags = argv.tags;
36-
37-
const result = await sdk.images.get({ id });
38-
id = result._id;
41+
const registry = argv.registry;
3942

4043
await Promise.each(tags, async (tag) => {
41-
await sdk.images.tag({ id, tag });
42-
console.log(`Tag: ${tag} was added successfully to image: ${id}`);
44+
await sdk.images.tag({ id, tag, registry });
45+
console.log(`Tag "${tag}" was added successfully to image "${id}" on "${registry || 'default'}" registry`);
4346
});
4447
},
4548
});

lib/interface/cli/commands/image/untag.cmd.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const untag = new Command({
88
command: 'untag <id> [tags..]',
99
category: 'Images',
1010
description: 'Untag an image',
11+
usage: 'Untagging an image will result in the removal of tag. If registry not specified - default is used',
1112
webDocs: {
1213
category: 'Images',
1314
title: 'Untag Image',
@@ -21,23 +22,24 @@ const untag = new Command({
2122
.positional('names', {
2223
description: 'Tag names',
2324
})
24-
.example('codefresh untag 2dfacdaad466 1.0.0', "Remove tag '1.0.0' from image '2dfacdaad466'")
25+
.option('registry', {
26+
alias: 'r',
27+
description: 'Registry integration name',
28+
})
29+
.example('codefresh untag 2dfacdaad466 1.0.0', "Remove tag '1.0.0' from image '2dfacdaad466' on default registry")
30+
.example('codefresh untag 2dfacdaad466 1.0.0 --registry dockerhub', "Remove tag '2dfacdaad466' with a new tag: '1.0.0' on dockerhub")
2531
.example('codefresh untag 2dfacdaad466 1.0.0 my-tag', "Remove tags '1.0.0' and 'my-tag' from image'2dfacdaad466'");
2632

2733
return yargs;
2834
},
2935
handler: async (argv) => {
30-
let id = argv.id;
36+
const id = argv.id;
3137
const tags = argv.tags;
32-
33-
const result = await sdk.images.get({ id });
34-
id = result._id;
38+
const registry = argv.registry;
3539

3640
await Promise.each(tags, async (tag) => {
37-
const foundTag = _.find(result.tags, info => info.tag == tag); // eslint-disable-line
38-
tag = foundTag && foundTag._id;
39-
await sdk.images.untag({ id, tag });
40-
console.log(`Tag: ${tag} was successfully removed from image: ${id}`);
41+
await sdk.images.untag({ id, tag, registry });
42+
console.log(`Tag "${tag}" was successfully removed from image "${id}" on "${registry || 'default'}" registry'`);
4143
});
4244
},
4345
});

lib/output/Output.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,25 @@ class Output {
6464
if (isDebug()) {
6565
console.error(error.stack);
6666
} else {
67-
console.error(`${error.toString()}`);
67+
console.error(this._extractErrorMessage(error));
6868
}
6969
}
70+
71+
static _extractErrorMessage(error) {
72+
if (_.isString(error.message)) {
73+
try {
74+
let json = JSON.parse(error.message);
75+
if (_.isString(json)) {
76+
json = JSON.parse(json);
77+
}
78+
const message = json.message || error.message;
79+
return message ? `Error: ${message}` : error.toString();
80+
} catch (e) {
81+
return error.toString();
82+
}
83+
}
84+
return error.toString();
85+
}
7086
}
7187

7288
module.exports = Output;

openapi.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4986,6 +4986,15 @@
49864986
"schema": {
49874987
"type": "string"
49884988
}
4989+
},
4990+
{
4991+
"description": "registry",
4992+
"in": "query",
4993+
"name": "registry",
4994+
"required": false,
4995+
"schema": {
4996+
"type": "string"
4997+
}
49894998
}
49904999
],
49915000
"responses": {
@@ -5019,6 +5028,15 @@
50195028
"schema": {
50205029
"type": "string"
50215030
}
5031+
},
5032+
{
5033+
"description": "registry",
5034+
"in": "query",
5035+
"name": "registry",
5036+
"required": false,
5037+
"schema": {
5038+
"type": "string"
5039+
}
50225040
}
50235041
],
50245042
"responses": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.63.14",
3+
"version": "0.64.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)