@@ -13,16 +13,11 @@ import (
1313)
1414
1515var tagCmd = cli.Command {
16- Name : "tag" ,
17- Usage : "Create a local image tag" ,
18- ArgsUsage : "<source> <target>" ,
19- Description : "Create a local image tag in Hypeman without pulling or converting the image." ,
20- Action : handleTag ,
21- HideHelpCommand : true ,
22- }
23-
24- type tagImageRequest struct {
25- Target string `json:"target"`
16+ Name : "tag" ,
17+ Usage : "Create a local image tag" ,
18+ ArgsUsage : "<source> <target>" ,
19+ Description : "Create a local image tag in Hypeman without pulling or converting the image." ,
20+ Action : handleTag ,
2621}
2722
2823func handleTag (ctx context.Context , cmd * cli.Command ) error {
@@ -33,30 +28,32 @@ func handleTag(ctx context.Context, cmd *cli.Command) error {
3328
3429 source , target := args [0 ], args [1 ]
3530 client := hypeman .NewClient (getDefaultRequestOptions (cmd )... )
31+ res , err := tagImage (ctx , cmd , & client , source , target )
32+ if err != nil {
33+ return err
34+ }
35+
36+ return printTagResult (cmd , target , res )
37+ }
3638
37- var opts []option.RequestOption
39+ func tagImage (ctx context.Context , cmd * cli.Command , client * hypeman.Client , source , target string ) ([]byte , error ) {
40+ var res []byte
41+ opts := []option.RequestOption {option .WithResponseBodyInto (& res )}
3842 if cmd .Root ().Bool ("debug" ) {
3943 opts = append (opts , debugMiddlewareOption )
4044 }
4145
42- var res []byte
43- opts = append (opts , option .WithResponseBodyInto (& res ))
4446 path := "/images/" + url .PathEscape (source ) + "/tag"
45- if err := client .Post (ctx , path , tagImageRequest {Target : target }, nil , opts ... ); err != nil {
46- if ! isNotFoundError (err ) {
47- return err
48- }
49-
50- // Keep the Docker fallback for sources that have not been imported into
51- // Hypeman yet. Once staged, the image is available under the requested
52- // target and can be pushed through the normal cached-image flow.
53- staged , stageErr := stageDockerImage (ctx , cmd , & client , source , target )
54- if stageErr != nil {
55- return fmt .Errorf ("image %q was not found in Hypeman; stage it from Docker: %w" , source , stageErr )
56- }
57- res = []byte (staged .RawJSON ())
47+ body := struct {
48+ Target string `json:"target"`
49+ }{Target : target }
50+ if err := client .Post (ctx , path , body , nil , opts ... ); err != nil {
51+ return nil , err
5852 }
53+ return res , nil
54+ }
5955
56+ func printTagResult (cmd * cli.Command , target string , res []byte ) error {
6057 format := cmd .Root ().String ("format" )
6158 transform := cmd .Root ().String ("transform" )
6259 result := gjson .ParseBytes (res )
0 commit comments