Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>wtf.metio.maven.parents</groupId>
<artifactId>maven-parents-java-stable</artifactId>
<version>2022.10.28</version>
<version>2022.11.25</version>
</parent>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
Expand Down Expand Up @@ -94,6 +94,11 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>wtf.metio.devcontainer</groupId>
<artifactId>devcontainer.java</artifactId>
<version>2022.12.7</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -155,7 +160,7 @@
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.6.3</version>
<version>4.7.0</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
Expand Down Expand Up @@ -195,7 +200,6 @@
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<extensions>true</extensions>
<version>0.9.18</version>
<executions>
<execution>
<id>build-native</id>
Expand Down Expand Up @@ -290,17 +294,17 @@
<mainClass>picocli.codegen.docgen.manpage.ManPageGenerator</mainClass>
<arguments>
<argument>--outdir=${project.build.directory}/generated-picocli-docs</argument>
<argument>wtf.metio.ilo.shell.Shell</argument>
<argument>wtf.metio.ilo.compose.Compose</argument>
<argument>wtf.metio.ilo.devcontainer.Devcontainer</argument>
<argument>wtf.metio.ilo.devfile.Devfile</argument>
<argument>wtf.metio.ilo.shell.ShellCommand</argument>
<argument>wtf.metio.ilo.compose.ComposeCommand</argument>
<argument>wtf.metio.ilo.devcontainer.DevcontainerCommand</argument>
<argument>wtf.metio.ilo.devfile.DevfileCommand</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.6.3</version>
<version>4.7.0</version>
<type>jar</type>
</dependency>
</dependencies>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
requires info.picocli;
requires com.fasterxml.jackson.databind;
requires com.fasterxml.jackson.dataformat.yaml;
requires wtf.metio.devcontainer;

opens wtf.metio.ilo to info.picocli;
opens wtf.metio.ilo.compose to info.picocli;
opens wtf.metio.ilo.devcontainer to info.picocli, com.fasterxml.jackson.databind;
opens wtf.metio.ilo.devcontainer to info.picocli;
opens wtf.metio.ilo.devfile to info.picocli, com.fasterxml.jackson.databind;
opens wtf.metio.ilo.shell to info.picocli;
opens wtf.metio.ilo.version to info.picocli;
Expand Down
46 changes: 23 additions & 23 deletions src/main/java/wtf/metio/ilo/Ilo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import picocli.AutoComplete;
import picocli.CommandLine;
import wtf.metio.ilo.cli.RunCommands;
import wtf.metio.ilo.compose.Compose;
import wtf.metio.ilo.devcontainer.Devcontainer;
import wtf.metio.ilo.devfile.Devfile;
import wtf.metio.ilo.compose.ComposeCommand;
import wtf.metio.ilo.devcontainer.DevcontainerCommand;
import wtf.metio.ilo.devfile.DevfileCommand;
import wtf.metio.ilo.errors.ExitCodes;
import wtf.metio.ilo.errors.PrintingExceptionHandler;
import wtf.metio.ilo.shell.Shell;
import wtf.metio.ilo.shell.ShellCommand;
import wtf.metio.ilo.version.VersionProvider;

import java.nio.file.Paths;
Expand All @@ -26,25 +26,25 @@
* Main entry point for ilo - a little tool to manage reproducible build environments
*/
@CommandLine.Command(
name = "ilo",
description = "Manage reproducible build environments",
versionProvider = VersionProvider.class,
mixinStandardHelpOptions = true,
showAtFileInUsageHelp = true,
usageHelpAutoWidth = true,
synopsisSubcommandLabel = "COMMAND",
descriptionHeading = "%n",
parameterListHeading = "%n",
optionListHeading = "%nOptions:%n",
commandListHeading = "%nCommands:%n",
subcommands = {
Shell.class,
Compose.class,
Devcontainer.class,
Devfile.class,
AutoComplete.GenerateCompletion.class
},
showDefaultValues = true
name = "ilo",
description = "Manage reproducible build environments",
versionProvider = VersionProvider.class,
mixinStandardHelpOptions = true,
showAtFileInUsageHelp = true,
usageHelpAutoWidth = true,
synopsisSubcommandLabel = "COMMAND",
descriptionHeading = "%n",
parameterListHeading = "%n",
optionListHeading = "%nOptions:%n",
commandListHeading = "%nCommands:%n",
subcommands = {
ShellCommand.class,
ComposeCommand.class,
DevcontainerCommand.class,
DevfileCommand.class,
AutoComplete.GenerateCompletion.class
},
showDefaultValues = true
)
public final class Ilo implements Runnable {

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/wtf/metio/ilo/cli/CommandLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public final class CommandLifecycle {
* <li>Cleanup</li>
* </ol>>
*
* @param tool The container tool to use, e.g. podman.
* @param options The options to use for the entire command lifecycle.
* @param executor The executor to use.
* @param tool The container tool to use, e.g. podman.
* @param options The options to use for the entire command lifecycle.
* @param executor The executor to use.
* @param <OPTIONS> The type of the options supplied.
* @param <CLI> The type of the container tool supplied.
* @param <CLI> The type of the container tool supplied.
* @return Stream of exit codes, one for each step in the lifecycle.
*/
public static <OPTIONS extends Options, CLI extends CliTool<OPTIONS>> int run(
final CLI tool,
final OPTIONS options,
final BiFunction<? super List<String>, ? super Boolean, Integer> executor) {
final CLI tool,
final OPTIONS options,
final BiFunction<? super List<String>, ? super Boolean, Integer> executor) {
final var pullArguments = tool.pullArguments(options);
final var pullExitCode = executor.apply(pullArguments, options.debug());
if (0 != pullExitCode) {
Expand All @@ -58,7 +58,7 @@ public static <OPTIONS extends Options, CLI extends CliTool<OPTIONS>> int run(
final var cleanupArguments = tool.cleanupArguments(options);
final var cleanupExitCode = executor.apply(cleanupArguments, options.debug());
return IntStream.of(pullExitCode, buildExitCode, runExitCode, cleanupExitCode)
.max().orElse(CommandLine.ExitCode.SOFTWARE);
.max().orElse(CommandLine.ExitCode.SOFTWARE);
}

private CommandLifecycle() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/wtf/metio/ilo/cli/Executables.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public final class Executables {
*/
public static Optional<Path> of(final String tool) {
return allPaths().map(path -> path.resolve(tool))
.filter(Executables::canExecute)
.findFirst();
.filter(Executables::canExecute)
.findFirst();
}

// visible for testing
static Stream<Path> allPaths() {
return Stream.of(System.getenv("PATH")
.split(Pattern.quote(File.pathSeparator)))
.map(Paths::get);
.split(Pattern.quote(File.pathSeparator)))
.map(Paths::get);
}

// visible for testing
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/wtf/metio/ilo/cli/RunCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public static Stream<String> locate(final Path baseDirectory) {

private static Stream<String> asArgumentFiles(final Stream<? extends Path> locations) {
return locations
.filter(Files::isReadable)
.filter(Files::isRegularFile)
.map(Path::toAbsolutePath)
.map(Path::toString)
.map("@"::concat);
.filter(Files::isReadable)
.filter(Files::isRegularFile)
.map(Path::toAbsolutePath)
.map(Path::toString)
.map("@"::concat);
}

/**
Expand All @@ -54,9 +54,9 @@ private static Stream<String> asArgumentFiles(final Stream<? extends Path> locat
public static boolean shouldAddRunCommands(final String[] args) {
final var hasArguments = 0 < args.length;
final var isVersion = (hasArguments && ("-V".equals(args[0]) || "--version".equals(args[0])))
|| 1 < args.length && ("-V".equals(args[1]) || "--version".equals(args[1]));
|| 1 < args.length && ("-V".equals(args[1]) || "--version".equals(args[1]));
final var isHelp = (hasArguments && ("-h".equals(args[0]) || "--help".equals(args[0])))
|| (1 < args.length && ("-h".equals(args[1]) || "--help".equals(args[1])));
|| (1 < args.length && ("-h".equals(args[1]) || "--help".equals(args[1])));
final var isCompletion = hasArguments && "generate-completion".equals(args[0]);
final var disableRunCommands = hasArguments && "--no-rc".equals(args[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
import java.util.concurrent.Callable;

@CommandLine.Command(
name = "compose",
description = "Open an (interactive) shell using podman-/docker-compose",
versionProvider = VersionProvider.class,
mixinStandardHelpOptions = true,
showAtFileInUsageHelp = true,
usageHelpAutoWidth = true,
showDefaultValues = true,
descriptionHeading = "%n",
optionListHeading = "%n"
name = "compose",
description = "Open an (interactive) shell using podman-/docker-compose",
versionProvider = VersionProvider.class,
mixinStandardHelpOptions = true,
showAtFileInUsageHelp = true,
usageHelpAutoWidth = true,
showDefaultValues = true,
descriptionHeading = "%n",
optionListHeading = "%n"
)
public final class Compose implements Callable<Integer> {
public final class ComposeCommand implements Callable<Integer> {

@CommandLine.Mixin
public ComposeOptions options;

private final CliExecutor<? super ComposeRuntime, ComposeCLI, ComposeOptions> executor;

// default constructor for picocli
public Compose() {
public ComposeCommand() {
this(new ComposeExecutor());
}

// constructor for testing
Compose(final CliExecutor<? super ComposeRuntime, ComposeCLI, ComposeOptions> executor) {
ComposeCommand(final CliExecutor<? super ComposeRuntime, ComposeCLI, ComposeOptions> executor) {
this.executor = executor;
}

Expand Down
59 changes: 30 additions & 29 deletions src/main/java/wtf/metio/ilo/compose/ComposeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,79 +15,80 @@
public final class ComposeOptions implements Options {

@CommandLine.Option(
names = {"--runtime"},
description = "Specify the runtime to use. If none is specified, use auto-selection.",
converter = ComposeRuntimeConverter.class
names = {"--runtime"},
description = "Specify the runtime to use. If none is specified, use auto-selection.",
converter = ComposeRuntimeConverter.class
)
public ComposeRuntime runtime;

@CommandLine.Option(
names = {"--no-interactive"},
description = "Allocate a pseudo TTY or not.",
defaultValue = "true",
negatable = true
names = {"--interactive"},
description = "Allocate a pseudo TTY or not.",
defaultValue = "true",
fallbackValue = "true",
negatable = true
)
public boolean interactive;

@CommandLine.Option(
names = {"--debug"},
description = "Show additional debug information."
names = {"--debug"},
description = "Show additional debug information."
)
public boolean debug;

@CommandLine.Option(
names = {"--pull"},
description = "Pull images before opening shell."
names = {"--pull"},
description = "Pull images before opening shell."
)
public boolean pull;

@CommandLine.Option(
names = {"--build"},
description = "Build images before opening shell."
names = {"--build"},
description = "Build images before opening shell."
)
public boolean build;

@CommandLine.Option(
names = {"--file"},
description = "Specify the docker-compose.yml/footloose.yaml file to use.",
defaultValue = "docker-compose.yml"
names = {"--file"},
description = "Specify the docker-compose.yml/footloose.yaml file to use.",
defaultValue = "docker-compose.yml"
)
public List<String> file;

@CommandLine.Option(
names = {"--runtime-option"},
description = "Options for the selected compose runtime itself."
names = {"--runtime-option"},
description = "Options for the selected compose runtime itself."
)
public List<String> runtimeOptions;

@CommandLine.Option(
names = {"--runtime-pull-option"},
description = "Options for the pull command of the selected compose runtime."
names = {"--runtime-pull-option"},
description = "Options for the pull command of the selected compose runtime."
)
public List<String> runtimePullOptions;

@CommandLine.Option(
names = {"--runtime-build-option"},
description = "Options for the build command of the selected compose runtime."
names = {"--runtime-build-option"},
description = "Options for the build command of the selected compose runtime."
)
public List<String> runtimeBuildOptions;

@CommandLine.Option(
names = {"--runtime-run-option"},
description = "Options for the run command of the selected compose runtime."
names = {"--runtime-run-option"},
description = "Options for the run command of the selected compose runtime."
)
public List<String> runtimeRunOptions;

@CommandLine.Option(
names = {"--runtime-cleanup-option"},
description = "Options for the cleanup command of the selected compose runtime."
names = {"--runtime-cleanup-option"},
description = "Options for the cleanup command of the selected compose runtime."
)
public List<String> runtimeCleanupOptions;

@CommandLine.Parameters(
index = "0",
description = "Specify the service to run.",
defaultValue = "dev"
index = "0",
description = "Specify the service to run.",
defaultValue = "dev"
)
public String service;

Expand Down
Loading