gnodet-bot commented on code in PR #28763:
URL: https://github.com/apache/camel/pull/28763#discussion_r4430977915


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java:
##########
@@ -152,155 +163,278 @@ public void execute(String... args) {
         quit(exitCode);
     }
 
+    /**
+     * The command of the CLI that a command line runs, when the CLI needs to 
create only that command: not for the
+     * help, a command line that starts with an option (such as 
<tt>--version</tt>), or the commands that use the other

Review Comment:
   💡 **Nit**: use `{@code}` instead of deprecated `<tt>` (three occurrences in 
this method's Javadoc: here, the `@return` line, and the `createCommandLine` 
`@param` below).
   
   ```suggestion
        * help, a command line that starts with an option (such as {@code 
--version}), or the commands that use the other
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java:
##########
@@ -152,155 +163,278 @@ public void execute(String... args) {
         quit(exitCode);
     }
 
+    /**
+     * The command of the CLI that a command line runs, when the CLI needs to 
create only that command: not for the
+     * help, a command line that starts with an option (such as 
<tt>--version</tt>), or the commands that use the other
+     * commands ({@link #FULL_COMMANDS}) or the plugins ({@link 
PluginHelper#isPluginConsumingCommand(String)}).
+     *
+     * @param  args the command line
+     * @return      the name of the command, or <tt>null</tt> to create all 
commands

Review Comment:
   ```suggestion
        * @return      the name of the command, or {@code null} to create all 
commands
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/PluginHelper.java:
##########
@@ -114,6 +114,17 @@ public static boolean shouldDiscoverPlugins(CommandLine 
commandLine, String... a
         return !commandLine.getSubcommands().containsKey(target);
     }
 
+    /**
+     * Whether the command of the CLI uses the plugins, so they are loaded 
when it runs (see
+     * {@link #shouldDiscoverPlugins(CommandLine, String...)}).
+     *
+     * @param  command the name of the command
+     * @return         <tt>true</tt> for shell, run, export and cmd

Review Comment:
   ```suggestion
        * @return         {@code true} for shell, run, export and cmd
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelJBangMain.java:
##########
@@ -152,155 +163,278 @@ public void execute(String... args) {
         quit(exitCode);
     }
 
+    /**
+     * The command of the CLI that a command line runs, when the CLI needs to 
create only that command: not for the
+     * help, a command line that starts with an option (such as 
<tt>--version</tt>), or the commands that use the other
+     * commands ({@link #FULL_COMMANDS}) or the plugins ({@link 
PluginHelper#isPluginConsumingCommand(String)}).
+     *
+     * @param  args the command line
+     * @return      the name of the command, or <tt>null</tt> to create all 
commands
+     */
+    static String onlyCommand(String... args) {
+        if (args == null || args.length == 0) {
+            return null;
+        }
+        String target = args[0];
+        if (target == null || target.isBlank() || target.startsWith("-") || 
FULL_COMMANDS.contains(target)
+                || PluginHelper.isPluginConsumingCommand(target)) {
+            return null;
+        }
+        for (String arg : args) {
+            if ("--help".equals(arg) || "-h".equals(arg)) {
+                // the help lists the plugins that are not installed, from all 
commands
+                return null;
+            }
+        }
+        return target;
+    }
+
+    /**
+     * Whether the command line has only the command of the CLI that it runs 
(see {@link #onlyCommand(String...)}), and
+     * not all the commands, so the commands of the plugins are not needed 
either.
+     *
+     * @param  commandLine the command line
+     * @param  args        the arguments it runs
+     * @return             <tt>true</tt> when it has only that command
+     */
+    public static boolean hasOnlyCommand(CommandLine commandLine, String... 
args) {
+        String only = onlyCommand(args);
+        return only != null && commandLine.getSubcommands().size() == 1 && 
commandLine.getSubcommands().containsKey(only);
+    }
+
+    private static boolean shouldCreate(String only, String name) {
+        return only == null || only.equals(name);
+    }
+
     /**
      * The command line with the commands of the CLI.
+     *
+     * @param only the name of the one command to create, or <tt>null</tt> for 
all commands

Review Comment:
   ```suggestion
        * @param only the name of the one command to create, or {@code null} 
for all commands
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to