All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.picocli.runtime.PicocliRunner Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.picocli.runtime;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.event.Event;

import io.quarkus.runtime.QuarkusApplication;
import picocli.CommandLine;

@Dependent
public class PicocliRunner implements QuarkusApplication {

    private static final class EventExecutionStrategy implements CommandLine.IExecutionStrategy {
        private final CommandLine.IExecutionStrategy executionStrategy;
        private final Event parseResultEvent;

        private EventExecutionStrategy(CommandLine.IExecutionStrategy executionStrategy,
                Event parseResultEvent) {
            this.executionStrategy = executionStrategy;
            this.parseResultEvent = parseResultEvent;
        }

        @Override
        public int execute(CommandLine.ParseResult parseResult)
                throws CommandLine.ExecutionException, CommandLine.ParameterException {
            parseResultEvent.fire(parseResult);
            return executionStrategy.execute(parseResult);
        }
    }

    private final CommandLine commandLine;

    public PicocliRunner(CommandLine commandLine, Event parseResultEvent) {
        this.commandLine = commandLine
                .setExecutionStrategy(new EventExecutionStrategy(commandLine.getExecutionStrategy(), parseResultEvent));
    }

    @Override
    public int run(String... args) throws Exception {
        try {
            return commandLine.execute(args);
        } finally {
            commandLine.getOut().flush();
            commandLine.getErr().flush();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy