This is an automated email from the ASF dual-hosted git repository.

kkloudas pushed a commit to branch release-1.12
in repository https://gitbox.apache.org/repos/asf/flink.git

commit 6c2fa6603cc1bd85f7a87322b229543ff62f62b8
Author: Aljoscha Krettek <[email protected]>
AuthorDate: Mon Nov 30 15:12:08 2020 +0100

    [refactor] Delegate option printing fully to CLIs
    
    Before, the "-t" option was hardcoded in CliFrontendParser although that
    option comes from GenericCLI.
    
    Now, print printHelpForRunApplication() has the same signature and
    behaviour as the other printHelp...() methods.
    
    This lessens coupling but introduces the problem that we now filter
    manually on the CLIs that support application mode in CliFrontendParser.
    
    If we really wanted we could add a "supportsApplicationMode()" flag to
    CLIs but I think that would be pushing it a bit.
---
 .../org/apache/flink/client/cli/CliFrontend.java     | 12 +++---------
 .../apache/flink/client/cli/CliFrontendParser.java   | 20 +++++++++++++++-----
 .../java/org/apache/flink/client/cli/GenericCLI.java | 12 ++++++++++--
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git 
a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java 
b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
index 27a2a51..4f69a36 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontend.java
@@ -176,7 +176,7 @@ public class CliFrontend {
                final CommandLine commandLine = getCommandLine(commandOptions, 
args, true);
 
                if (commandLine.hasOption(HELP_OPTION.getOpt())) {
-                       
CliFrontendParser.printHelpForRunApplication(getApplicationModeTargetNames());
+                       
CliFrontendParser.printHelpForRunApplication(customCommandLines);
                        return;
                }
 
@@ -207,12 +207,6 @@ public class CliFrontend {
                deployer.run(effectiveConfiguration, applicationConfiguration);
        }
 
-       private static String getApplicationModeTargetNames() {
-               return new 
DefaultClusterClientServiceLoader().getApplicationModeTargetNames()
-                               .map(name -> String.format("\"%s\"", name))
-                               .collect(Collectors.joining(", "));
-       }
-
        /**
         * Executions the run action.
         *
@@ -959,7 +953,7 @@ public class CliFrontend {
 
                // check for action
                if (args.length < 1) {
-                       CliFrontendParser.printHelp(customCommandLines, 
getApplicationModeTargetNames());
+                       CliFrontendParser.printHelp(customCommandLines);
                        System.out.println("Please specify an action.");
                        return 1;
                }
@@ -996,7 +990,7 @@ public class CliFrontend {
                                        return 0;
                                case "-h":
                                case "--help":
-                                       
CliFrontendParser.printHelp(customCommandLines, 
getApplicationModeTargetNames());
+                                       
CliFrontendParser.printHelp(customCommandLines);
                                        return 0;
                                case "-v":
                                case "--version":
diff --git 
a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
 
b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
index a5c37ab..c4a2623 100644
--- 
a/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
+++ 
b/flink-clients/src/main/java/org/apache/flink/client/cli/CliFrontendParser.java
@@ -31,6 +31,8 @@ import org.apache.commons.cli.ParseException;
 import javax.annotation.Nullable;
 
 import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * A simple command line parser (based on Apache Commons CLI) that extracts 
command
@@ -341,13 +343,13 @@ public class CliFrontendParser {
        /**
         * Prints the help for the client.
         */
-       public static void printHelp(Collection<CustomCommandLine> 
customCommandLines, String availableApplicationModeTargets) {
+       public static void printHelp(Collection<CustomCommandLine> 
customCommandLines) {
                System.out.println("./flink <ACTION> [OPTIONS] [ARGUMENTS]");
                System.out.println();
                System.out.println("The following actions are available:");
 
                printHelpForRun(customCommandLines);
-               printHelpForRunApplication(availableApplicationModeTargets);
+               printHelpForRunApplication(customCommandLines);
                printHelpForInfo();
                printHelpForList(customCommandLines);
                printHelpForStop(customCommandLines);
@@ -372,15 +374,23 @@ public class CliFrontendParser {
                System.out.println();
        }
 
-       public static void printHelpForRunApplication(String 
availableApplicationModeTargets) {
+       public static void 
printHelpForRunApplication(Collection<CustomCommandLine> customCommandLines) {
                HelpFormatter formatter = new HelpFormatter();
                formatter.setLeftPadding(5);
                formatter.setWidth(80);
 
                System.out.println("\nAction \"run-application\" runs an 
application in Application Mode.");
-               System.out.println("\n  Syntax: run-application -t [" + 
availableApplicationModeTargets + "] [OPTIONS] <jar-file> <arguments>");
+               System.out.println("\n  Syntax: run-application [OPTIONS] 
<jar-file> <arguments>");
                formatter.setSyntaxPrefix("  \"run-application\" action 
options:");
-               formatter.printHelp(" ", new 
Options().addOption(DynamicPropertiesUtil.DYNAMIC_PROPERTIES));
+
+               // Only GenericCLI works with application mode, the other CLIs 
will be phased out
+               // in the future
+               List<CustomCommandLine> filteredCommandLines = 
customCommandLines
+                               .stream()
+                               .filter((cli) -> cli instanceof GenericCLI)
+                               .collect(Collectors.toList());
+
+               printCustomCliOptions(filteredCommandLines, formatter, true);
                System.out.println();
        }
 
diff --git 
a/flink-clients/src/main/java/org/apache/flink/client/cli/GenericCLI.java 
b/flink-clients/src/main/java/org/apache/flink/client/cli/GenericCLI.java
index d010034..63181e7 100644
--- a/flink-clients/src/main/java/org/apache/flink/client/cli/GenericCLI.java
+++ b/flink-clients/src/main/java/org/apache/flink/client/cli/GenericCLI.java
@@ -19,6 +19,7 @@
 package org.apache.flink.client.cli;
 
 import org.apache.flink.annotation.Internal;
+import org.apache.flink.client.deployment.DefaultClusterClientServiceLoader;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.configuration.DeploymentOptions;
 import org.apache.flink.configuration.DeploymentOptionsInternal;
@@ -53,8 +54,9 @@ public class GenericCLI implements CustomCommandLine {
 
        private final Option targetOption = new Option("t", "target", true,
                        "The deployment target for the given application, which 
is equivalent " +
-                                       "to the \"" + 
DeploymentOptions.TARGET.key() + "\" config option. The " +
-                                       "currently available targets are: " + 
getExecutorFactoryNames() + ".");
+                                       "to the \"" + 
DeploymentOptions.TARGET.key() + "\" config option. For the \"run\" action the 
" +
+                                       "currently available targets are: " + 
getExecutorFactoryNames() + ". For the \"run-application\" action"
+                                       + " the currently available targets 
are: " + getApplicationModeTargetNames() + ".");
 
        private final Configuration configuration;
 
@@ -114,4 +116,10 @@ public class GenericCLI implements CustomCommandLine {
                                .map(name -> String.format("\"%s\"", name))
                                .collect(Collectors.joining(", "));
        }
+
+       private static String getApplicationModeTargetNames() {
+               return new 
DefaultClusterClientServiceLoader().getApplicationModeTargetNames()
+                               .map(name -> String.format("\"%s\"", name))
+                               .collect(Collectors.joining(", "));
+       }
 }

Reply via email to