11const Command = require ( '../../Command' ) ;
2- const { parseFamiliarName } = require ( '@codefresh-io/docker-reference' ) ;
32const annotateRoot = require ( '../root/annotate.cmd' ) ;
4- const CFError = require ( 'cf-errors' ) ;
5- const { sdk } = require ( '../../../../logic' ) ;
63const annotationLogic = require ( '../annotation/annotation.logic' ) ;
74
85const command = new Command ( {
@@ -27,32 +24,11 @@ const command = new Command({
2724 array : true ,
2825 } )
2926 . example ( 'codefresh annotate image 2dfacdaad466 -l coverage=75%' , 'Annotate an image with a single label' )
30- . example ( 'codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true' , 'Annotate an image with multiple labels' ) ;
27+ . example ( 'codefresh annotate image 2dfacdaad466 -l coverage=75% -l tests_passed=true' , 'Annotate an image with multiple labels' )
28+ . example ( 'codefresh annotate image codefresh/cli:latest -l coverage=75% -l tests_passed=true' , 'Annotate an image by name with multiple labels' ) ;
3129 } ,
3230 handler : async ( argv ) => {
33- let dockerImageId = argv . id ;
34- const useFullName = dockerImageId . includes ( ':' ) ;
35-
36- if ( useFullName ) {
37- const { repository, tag } = parseFamiliarName ( dockerImageId ) ;
38- const results = await sdk . images . list ( {
39- imageDisplayNameRegex : repository ,
40- tag,
41- select : 'internalImageId' ,
42- } ) ;
43-
44- if ( ! results . length ) {
45- throw new CFError ( 'Image does not exist' ) ;
46- }
47-
48- if ( results . length > 1 ) {
49- throw new CFError ( `Could not get image id. ${ results . length } images found.` ) ;
50- }
51-
52- dockerImageId = results [ 0 ] . internalImageId ;
53- }
54-
55- await annotationLogic . createAnnotations ( { entityId : dockerImageId , entityType : 'image' , labels : argv . label } ) ;
31+ await annotationLogic . createAnnotations ( { entityId : argv . id , entityType : 'image' , labels : argv . label } ) ;
5632 console . log ( 'Annotations added successfully' ) ;
5733 } ,
5834} ) ;
0 commit comments