From 8fee869be2bb257ae98b4a5a328826a95d757f04 Mon Sep 17 00:00:00 2001 From: Danilo Ambrosio Date: Thu, 14 Oct 2021 01:35:24 -0300 Subject: [PATCH] Synchronized to docs --- README.md | 16 +------------ .../cli/CommandLineInterfaceInitializer.java | 7 +----- .../xoom/cli/UnknownCommandException.java | 4 ---- .../java/io/vlingo/xoom/cli/task/Task.java | 5 ++-- .../io/vlingo/xoom/cli/task/TaskTest.java | 23 ++++++++++--------- 5 files changed, 17 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index ca9bcc08..e292a78e 100644 --- a/README.md +++ b/README.md @@ -257,18 +257,4 @@ 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/. -# io.vlingo.bookstore -## Convert to Gradle Build - -``` -$ cd {project-folder} -$ gradle init -``` -# io.vlingo.bookstore -## Convert to Gradle Build - -``` -$ cd {project-folder} -$ gradle init -``` +one at https://mozilla.org/MPL/2.0/. \ No newline at end of file diff --git a/src/main/java/io/vlingo/xoom/cli/CommandLineInterfaceInitializer.java b/src/main/java/io/vlingo/xoom/cli/CommandLineInterfaceInitializer.java index 8fcd80e6..976e12c9 100644 --- a/src/main/java/io/vlingo/xoom/cli/CommandLineInterfaceInitializer.java +++ b/src/main/java/io/vlingo/xoom/cli/CommandLineInterfaceInitializer.java @@ -23,12 +23,7 @@ public class CommandLineInterfaceInitializer { public static void main(final String[] args) { ComponentsRegistration.registerWith(logger, new DefaultCommandExecutionProcess(logger), loadProperties(args)); - - final Task task = - Task.triggeredBy(resolveCommand(args)) - .orElseThrow(() -> new UnknownCommandException(args)); - - runTask(task, Arrays.asList(args)); + runTask(Task.triggeredBy(resolveCommand(args)), Arrays.asList(args)); } private static void runTask(final Task task, diff --git a/src/main/java/io/vlingo/xoom/cli/UnknownCommandException.java b/src/main/java/io/vlingo/xoom/cli/UnknownCommandException.java index 62fcc1f8..ade9aeb7 100644 --- a/src/main/java/io/vlingo/xoom/cli/UnknownCommandException.java +++ b/src/main/java/io/vlingo/xoom/cli/UnknownCommandException.java @@ -16,8 +16,4 @@ public UnknownCommandException(final String command) { super("The informed command is not supported " + command); } - public UnknownCommandException(final Object args) { - super("The informed command does not support arguments type " + args.getClass()); - } - } diff --git a/src/main/java/io/vlingo/xoom/cli/task/Task.java b/src/main/java/io/vlingo/xoom/cli/task/Task.java index 5ca320e7..31a67c15 100644 --- a/src/main/java/io/vlingo/xoom/cli/task/Task.java +++ b/src/main/java/io/vlingo/xoom/cli/task/Task.java @@ -7,6 +7,7 @@ package io.vlingo.xoom.cli.task; import io.vlingo.xoom.cli.CommandNotFoundException; +import io.vlingo.xoom.cli.UnknownCommandException; import io.vlingo.xoom.cli.option.Option; import io.vlingo.xoom.cli.option.OptionName; import io.vlingo.xoom.cli.option.OptionValue; @@ -38,10 +39,10 @@ protected Task(final String command, public abstract void run(final List args); - public static Optional triggeredBy(final String command) { + public static Task triggeredBy(final String command) { return allTasks().stream() .filter(task -> command != null && task.matchCommand(command.trim())) - .findFirst(); + .findFirst().orElseThrow(() -> new UnknownCommandException(command)); } public static String resolveDefaultCommand() { diff --git a/src/test/java/io/vlingo/xoom/cli/task/TaskTest.java b/src/test/java/io/vlingo/xoom/cli/task/TaskTest.java index 2289109d..c0329d6c 100644 --- a/src/test/java/io/vlingo/xoom/cli/task/TaskTest.java +++ b/src/test/java/io/vlingo/xoom/cli/task/TaskTest.java @@ -2,6 +2,7 @@ import io.vlingo.xoom.actors.Logger; import io.vlingo.xoom.cli.ComponentsRegistration; +import io.vlingo.xoom.cli.UnknownCommandException; import io.vlingo.xoom.cli.XoomTurboProperties; import io.vlingo.xoom.cli.XoomTurboProperties.ProjectPath; import io.vlingo.xoom.cli.task.designer.DesignerTask; @@ -33,17 +34,17 @@ public void setUp() { @Test public void testThatTasksAreFoundByCommand() { - Assertions.assertEquals(DesignerTask.class, Task.triggeredBy("gui").get().getClass()); - Assertions.assertEquals(DesignerTask.class, Task.triggeredBy("designer").get().getClass()); - Assertions.assertEquals(DockerPushTask.class, Task.triggeredBy("docker push").get().getClass()); - Assertions.assertEquals(DockerPackageTask.class, Task.triggeredBy("docker package").get().getClass()); - Assertions.assertEquals(DockerStatusTask.class, Task.triggeredBy("docker status").get().getClass()); - Assertions.assertEquals(GlooInitTask.class, Task.triggeredBy("gloo init").get().getClass()); - Assertions.assertEquals(GlooRouteTask.class, Task.triggeredBy("gloo route").get().getClass()); - Assertions.assertEquals(GlooSuspendTask.class, Task.triggeredBy("gloo suspend").get().getClass()); - Assertions.assertEquals(KubernetesPushTask.class, Task.triggeredBy("k8s push").get().getClass()); - Assertions.assertEquals(VersionDisplayTask.class, Task.triggeredBy("-version").get().getClass()); - Assertions.assertFalse(Task.triggeredBy("start").isPresent()); + Assertions.assertEquals(DesignerTask.class, Task.triggeredBy("gui").getClass()); + Assertions.assertEquals(DesignerTask.class, Task.triggeredBy("designer").getClass()); + Assertions.assertEquals(DockerPushTask.class, Task.triggeredBy("docker push").getClass()); + Assertions.assertEquals(DockerPackageTask.class, Task.triggeredBy("docker package").getClass()); + Assertions.assertEquals(DockerStatusTask.class, Task.triggeredBy("docker status").getClass()); + Assertions.assertEquals(GlooInitTask.class, Task.triggeredBy("gloo init").getClass()); + Assertions.assertEquals(GlooRouteTask.class, Task.triggeredBy("gloo route").getClass()); + Assertions.assertEquals(GlooSuspendTask.class, Task.triggeredBy("gloo suspend").getClass()); + Assertions.assertEquals(KubernetesPushTask.class, Task.triggeredBy("k8s push").getClass()); + Assertions.assertEquals(VersionDisplayTask.class, Task.triggeredBy("-version").getClass()); + Assertions.assertThrows(UnknownCommandException.class, () -> Task.triggeredBy("start")); } @Test