Repository: syncope
Updated Branches:
  refs/heads/master ae88f405f -> 4133c2402


http://git-wip-us.apache.org/repos/asf/syncope/blob/4133c240/client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
deleted file mode 100644
index 0442897..0000000
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/UsageMessages.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.client.cli.messages;
-
-public final class UsageMessages {
-
-    private static final String OPTION_COMMAND_MESSAGE_TEMPLATE = "\n - Usage: 
%s\n";
-
-    public static String optionCommandMessage(final String message) {
-        return String.format(OPTION_COMMAND_MESSAGE_TEMPLATE, message);
-    }
-
-    public static void printErrorMessage(final String... errors) {
-        final StringBuilder errorMessage = new StringBuilder("\n").append(" - 
");
-        for (final String error : errors) {
-            errorMessage.append(error).append("\n");
-        }
-        System.out.println(errorMessage.toString());
-    }
-
-    private UsageMessages() {
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/4133c240/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java 
b/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
new file mode 100644
index 0000000..2007743
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/util/CommandUtils.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.cli.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.syncope.client.cli.Command;
+import org.apache.syncope.client.cli.CommandClassScanner;
+import org.apache.syncope.client.cli.commands.AbstractCommand;
+
+public final class CommandUtils {
+
+    public static AbstractCommand fromArgs(final String arg)
+            throws InstantiationException, IllegalAccessException, 
IllegalArgumentException {
+
+        final CommandClassScanner ccs = new CommandClassScanner();
+        final List<Class<? extends AbstractCommand>> commands = 
ccs.getComponentClasses();
+
+        Class<? extends AbstractCommand> commandClass = null;
+        for (final Class<? extends AbstractCommand> cmd : commands) {
+            if (arg.equals(cmd.getAnnotation(Command.class).name())) {
+                commandClass = cmd;
+            }
+        }
+
+        if (commandClass == null) {
+            throw new IllegalArgumentException(arg + " is not a valid 
command");
+        }
+
+        return commandClass.newInstance();
+
+    }
+
+    public static List<AbstractCommand> commands()
+            throws InstantiationException, IllegalAccessException, 
IllegalArgumentException {
+
+        final List<AbstractCommand> listCommands = new ArrayList<>();
+
+        final CommandClassScanner ccs = new CommandClassScanner();
+        final List<Class<? extends AbstractCommand>> commands = 
ccs.getComponentClasses();
+
+        Class<? extends AbstractCommand> commandClass = null;
+        for (final Class<? extends AbstractCommand> cmd : commands) {
+            commandClass = cmd;
+            if (commandClass == null) {
+                throw new IllegalArgumentException();
+            }
+            listCommands.add(commandClass.newInstance());
+        }
+
+        return listCommands;
+    }
+
+    private CommandUtils() {
+
+    }
+
+}

Reply via email to