@Override
    public Integer doCall() throws Exception {
        // Operator id must be set
        if (ObjectHelper.isEmpty(operatorId)) {
            printer().println("Operator id must be set");
            return -1;
        }

        delegate.setFile(name);
        delegate.setSource(source);
        delegate.setSink(sink);
        delegate.setSteps(steps);
        delegate.setErrorHandler(errorHandler);
        delegate.setProperties(properties);

        String pipe = delegate.constructPipe();

        if (pipe.isEmpty()) {
            // Error in delegate exit now
            printer().println("Failed to construct Pipe resource");
            return -1;
        }

        // --operator-id={id} is a syntax sugar for '--annotation camel.apache.org/operator.id={id}'
        if (annotations == null) {
            annotations = new String[] { "%s=%s".formatted(CamelKCommand.OPERATOR_ID_LABEL, operatorId) };
        } else {
            annotations = Arrays.copyOf(annotations, annotations.length + 1);
            annotations[annotations.length - 1] = "%s=%s".formatted(CamelKCommand.OPERATOR_ID_LABEL, operatorId);
        }

        String annotationsContext = "";
        if (annotations != null) {
            StringBuilder sb = new StringBuilder("  annotations:\n");

            for (String annotation : annotations) {
                String[] keyValue = annotation.split("=", 2);
                if (keyValue.length != 2) {
                    printer().printf(
                            "annotation '%s' does not follow format <key>=<value>%n",
                            annotation);
                    continue;
                }

                sb.append("    ").append(keyValue[0]).append(": ").append(keyValue[1]).append("\n");
            }

            annotationsContext = sb.toString();
        }

        pipe = pipe.replaceFirst("\\{\\{ \\.Annotations }}\n", annotationsContext);

        String integrationSpec = "";
        Traits traitsSpec = null;
        if (traits != null && traits.length > 0) {
            traitsSpec = TraitHelper.parseTraits(traits);
        }

        if (connects != null) {
            if (traitsSpec == null) {
                traitsSpec = new Traits();
            }
            TraitHelper.configureConnects(traitsSpec, connects);
        }

        if (traitsSpec != null) {
            String traitYaml = KubernetesHelper.dumpYaml(traitsSpec);
            traitYaml = traitYaml.replaceAll("\n", "\n        ");
            integrationSpec = "  integration:\n    spec:\n      traits:\n        %s\n".formatted(traitYaml.trim());
        }

        pipe = pipe.replaceFirst("\\{\\{ \\.IntegrationSpec }}\n", integrationSpec);

        if (output != null) {
            delegate.setOutput(output);
            return delegate.dumpPipe(pipe);
        }

        Pipe pipeResource = KubernetesHelper.yaml(this.getClass().getClassLoader()).loadAs(pipe, Pipe.class);
        final AtomicBoolean updated = new AtomicBoolean(false);
        client(Pipe.class).resource(pipeResource).createOr(it -> {
            updated.set(true);
            return it.update();
        });

        if (updated.get()) {
            printer().printf("Pipe %s updated%n", pipeResource.getMetadata().getName());
        } else {
            printer().printf("Pipe %s created%n", pipeResource.getMetadata().getName());
        }

        if (wait || logs) {
            client(Pipe.class).withName(pipeResource.getMetadata().getName())
                    .waitUntilCondition(it -> "Running".equals(it.getStatus().getPhase()), 10, TimeUnit.MINUTES);
        }

        if (logs) {
            IntegrationLogs logsCommand = new IntegrationLogs(getMain());
            logsCommand.withClient(client());
            logsCommand.withName(pipeResource.getMetadata().getName());
            logsCommand.doCall();
        }

        return 0;
    }
@Test
    public void shouldCreatePipe() throws Exception {
        Bind command = createCommand("timer", "http");
        command.output = null;
        command.doCall();

        Assertions.assertEquals("Pipe timer-to-http created", printer.getOutput());

        Pipe created = kubernetesClient.resources(Pipe.class).withName("timer-to-http").get();
        Assertions.assertEquals("camel-k", created.getMetadata().getAnnotations().get(CamelKCommand.OPERATOR_ID_LABEL));
    }