Skip to content

Commit

Permalink
Synchronized to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-ambrosio committed Oct 20, 2021
1 parent 94143e5 commit 233f3dd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
package io.vlingo.xoom.cli;

import io.vlingo.xoom.actors.Logger;
import io.vlingo.xoom.cli.XoomTurboProperties.ProjectPath;
import io.vlingo.xoom.cli.option.Option;
import io.vlingo.xoom.cli.option.OptionName;
import io.vlingo.xoom.cli.option.OptionValue;
import io.vlingo.xoom.cli.task.Task;
import io.vlingo.xoom.cli.XoomTurboProperties.ProjectPath;
import io.vlingo.xoom.terminal.DefaultCommandExecutionProcess;

import java.util.Arrays;
Expand All @@ -26,7 +26,7 @@ public static void main(final String[] args) {
runTask(Task.triggeredBy(resolveCommand(args)), Arrays.asList(args));
}

private static void runTask(final Task task,
static void runTask(final Task task,
final List<String> args) {
try {
task.run(args);
Expand All @@ -40,17 +40,21 @@ private static void runTask(final Task task,
}
}

private static String resolveCommand(final String[] args) {
static String resolveCommand(final String[] args) {
if(args.length > 0) {
if(args.length == 1 || !Task.isCommand(args[1])) {
return args[0];
if(isCompositeCommand(args)) {
return args[0] + " " + args[1];
}
return args[0] + " " + args[1];
return args[0];
}
return Task.resolveDefaultCommand();
}

private static XoomTurboProperties loadProperties(final String[] args) {
static boolean isCompositeCommand(final String[] args) {
return args.length > 1 && Task.isCommand(args[1]);
}

static XoomTurboProperties loadProperties(final String[] args) {
final Option projectDirectory =
Option.of(OptionName.CURRENT_DIRECTORY, System.getProperty("user.dir"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © 2012-2021 VLINGO LABS. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.
package io.vlingo.xoom.cli;

import io.vlingo.xoom.actors.Logger;
import io.vlingo.xoom.terminal.CommandRetainer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CommandLineInterfaceInitializerTest {

@BeforeEach
public void setUp() {
ComponentsRegistration.registerWith(Logger.noOpLogger(), new CommandRetainer(), XoomTurboProperties.empty());
}

@Test
public void testThatCommandIsResolved() {
Assertions.assertEquals("designer", CommandLineInterfaceInitializer.resolveCommand(new String[]{}));
Assertions.assertEquals("designer", CommandLineInterfaceInitializer.resolveCommand(new String[]{"designer"}));
Assertions.assertEquals("designer", CommandLineInterfaceInitializer.resolveCommand(new String[]{"designer", "--target", "filesystem", "--profile", "test"}));
Assertions.assertEquals("docker package", CommandLineInterfaceInitializer.resolveCommand(new String[]{"docker", "package"}));
Assertions.assertEquals("docker package", CommandLineInterfaceInitializer.resolveCommand(new String[]{"docker", "package", "--tag", "latest"}));
}

}

0 comments on commit 233f3dd

Please sign in to comment.