fix: extract helpers to reduce cyclomatic complexity in attachments push
- commit
- aa8f6c2f45fd2d9230f805d6db031350ee2afafd
- author
- brice · · 2026-03-14 09:50 UTC
- parent
- 1e66d5a
- signature
- unsigned
1 file · +17 -12
M internal/adapters/in/cli/attachments_push.go +17 -12
| @@ -77,6 +77,18 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p | |||
| 77 | 77 | ||
| 78 | 78 | versionRef, latestRef := resolveImageRefs(registry, imageName, version) | |
| 79 | 79 | ||
| 80 | + | if err := printAttachmentPushInfo(out, imageArg, targets, versionRef, latestRef, version); err != nil { | |
| 81 | + | return err | |
| 82 | + | } | |
| 83 | + | ||
| 84 | + | if err := performAttachmentPush(ctx, build, version, platform, dockerfile, buildArgs, registry, imageName, versionRef, latestRef); err != nil { | |
| 85 | + | return err | |
| 86 | + | } | |
| 87 | + | ||
| 88 | + | return cliWriteLine(out, styles.RenderSuccess("Push complete")) | |
| 89 | + | } | |
| 90 | + | ||
| 91 | + | func printAttachmentPushInfo(out io.Writer, imageArg string, targets []string, versionRef, latestRef, version string) error { | |
| 80 | 92 | if err := cliWritef(out, "Attachment image: %s\n", styles.Theme.Bold.Render(imageArg)); err != nil { | |
| 81 | 93 | return err | |
| 82 | 94 | } | |
| @@ -91,21 +103,14 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p | |||
| 91 | 103 | return err | |
| 92 | 104 | } | |
| 93 | 105 | } | |
| 106 | + | return nil | |
| 107 | + | } | |
| 94 | 108 | ||
| 109 | + | func performAttachmentPush(ctx context.Context, build bool, version, platform, dockerfile string, buildArgs []string, registry, imageName, versionRef, latestRef string) error { | |
| 95 | 110 | if build { | |
| 96 | - | if err := buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef); err != nil { | |
| 97 | - | return err | |
| 98 | - | } | |
| 99 | - | } else { | |
| 100 | - | if err := tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef); err != nil { | |
| 101 | - | return err | |
| 102 | - | } | |
| 111 | + | return buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef) | |
| 103 | 112 | } | |
| 104 | - | ||
| 105 | - | if err := cliWriteLine(out, styles.RenderSuccess("Push complete")); err != nil { | |
| 106 | - | return err | |
| 107 | - | } | |
| 108 | - | return nil | |
| 113 | + | return tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef) | |
| 109 | 114 | } | |
| 110 | 115 | ||
| 111 | 116 | func resolveAttachmentImage(ctx context.Context, cp ControlPlane, imageArg string) (registry, imageName string, targets []string, err error) { | |
| @@ -77,6 +77,18 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p | |||||
| 77 | 77 | ||||
| 78 | versionRef, latestRef := resolveImageRefs(registry, imageName, version) | 78 | versionRef, latestRef := resolveImageRefs(registry, imageName, version) | ||
| 79 | 79 | ||||
| 80 | + | if err := printAttachmentPushInfo(out, imageArg, targets, versionRef, latestRef, version); err != nil { | |||
| 81 | + | return err | |||
| 82 | + | } | |||
| 83 | + | ||||
| 84 | + | if err := performAttachmentPush(ctx, build, version, platform, dockerfile, buildArgs, registry, imageName, versionRef, latestRef); err != nil { | |||
| 85 | + | return err | |||
| 86 | + | } | |||
| 87 | + | ||||
| 88 | + | return cliWriteLine(out, styles.RenderSuccess("Push complete")) | |||
| 89 | + | } | |||
| 90 | + | ||||
| 91 | + | func printAttachmentPushInfo(out io.Writer, imageArg string, targets []string, versionRef, latestRef, version string) error { | |||
| 80 | if err := cliWritef(out, "Attachment image: %s\n", styles.Theme.Bold.Render(imageArg)); err != nil { | 92 | if err := cliWritef(out, "Attachment image: %s\n", styles.Theme.Bold.Render(imageArg)); err != nil { | ||
| 81 | return err | 93 | return err | ||
| 82 | } | 94 | } | ||
| @@ -91,21 +103,14 @@ func runAttachmentsPush(ctx context.Context, imageArg, tag string, build bool, p | |||||
| 91 | return err | 103 | return err | ||
| 92 | } | 104 | } | ||
| 93 | } | 105 | } | ||
| 106 | + | return nil | |||
| 107 | + | } | |||
| 94 | 108 | ||||
| 109 | + | func performAttachmentPush(ctx context.Context, build bool, version, platform, dockerfile string, buildArgs []string, registry, imageName, versionRef, latestRef string) error { | |||
| 95 | if build { | 110 | if build { | ||
| 96 | - | if err := buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef); err != nil { | 111 | + | return buildAndPushFn(ctx, version, platform, dockerfile, buildArgs, versionRef, latestRef) |
| 97 | - | return err | |||
| 98 | - | } | |||
| 99 | - | } else { | |||
| 100 | - | if err := tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef); err != nil { | |||
| 101 | - | return err | |||
| 102 | - | } | |||
| 103 | } | 112 | } | ||
| 104 | - | 113 | + | return tagAndPushFn(ctx, registry, imageName, version, versionRef, latestRef) | |
| 105 | - | if err := cliWriteLine(out, styles.RenderSuccess("Push complete")); err != nil { | |||
| 106 | - | return err | |||
| 107 | - | } | |||
| 108 | - | return nil | |||
| 109 | } | 114 | } | ||
| 110 | 115 | ||||
| 111 | func resolveAttachmentImage(ctx context.Context, cp ControlPlane, imageArg string) (registry, imageName string, targets []string, err error) { | 116 | func resolveAttachmentImage(ctx context.Context, cp ControlPlane, imageArg string) (registry, imageName string, targets []string, err error) { | ||