From a0cd316f592c61dfa4eb9726ccb29660031dedd5 Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Sat, 16 May 2020 11:16:12 +0100 Subject: [PATCH] Move "dump config" flags to a more sensible place --- .../selenium/grid/TemplateGridCommand.java | 5 ++- .../selenium/grid/config/ConfigFlags.java | 33 +++++++++++++++++++ .../selenium/grid/server/HelpFlags.java | 27 --------------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/java/server/src/org/openqa/selenium/grid/TemplateGridCommand.java b/java/server/src/org/openqa/selenium/grid/TemplateGridCommand.java index 3666f5844b5c0..fb7a705c1311c 100644 --- a/java/server/src/org/openqa/selenium/grid/TemplateGridCommand.java +++ b/java/server/src/org/openqa/selenium/grid/TemplateGridCommand.java @@ -20,16 +20,15 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.ParameterException; import com.beust.jcommander.internal.DefaultConsole; - import com.google.common.collect.Sets; import org.openqa.selenium.cli.CliCommand; -import org.openqa.selenium.grid.config.HasRoles; import org.openqa.selenium.grid.config.AnnotatedConfig; import org.openqa.selenium.grid.config.CompoundConfig; import org.openqa.selenium.grid.config.ConcatenatingConfig; import org.openqa.selenium.grid.config.Config; import org.openqa.selenium.grid.config.ConfigFlags; import org.openqa.selenium.grid.config.EnvConfig; +import org.openqa.selenium.grid.config.HasRoles; import org.openqa.selenium.grid.log.LoggingOptions; import org.openqa.selenium.grid.server.HelpFlags; @@ -84,7 +83,7 @@ public final Executable configure(PrintStream out, PrintStream err, String... ar Config config = new CompoundConfig(allConfigs.toArray(new Config[0])); - if (helpFlags.dumpConfig(config, out)) { + if (configFlags.dumpConfig(config, out)) { return; } diff --git a/java/server/src/org/openqa/selenium/grid/config/ConfigFlags.java b/java/server/src/org/openqa/selenium/grid/config/ConfigFlags.java index 099b1acf0978b..0d7492bb85238 100644 --- a/java/server/src/org/openqa/selenium/grid/config/ConfigFlags.java +++ b/java/server/src/org/openqa/selenium/grid/config/ConfigFlags.java @@ -19,15 +19,25 @@ import com.beust.jcommander.Parameter; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import org.openqa.selenium.json.Json; +import java.io.PrintStream; import java.nio.file.Path; import java.util.List; +import java.util.Map; +import java.util.TreeMap; public class ConfigFlags { + private static final ImmutableSet IGNORED_SECTIONS = ImmutableSet.of("java", "lc", "term"); + @Parameter(names = "--config", description = "Config file to read from (may be specified more than once)") private List configFiles; + @Parameter(names = "--dump-config", description = "Dump the config of the server as JSON.", hidden = true) + private boolean dumpConfig; + public Config readConfigFiles() { if (configFiles == null || configFiles.isEmpty()) { return new MapConfig(ImmutableMap.of()); @@ -38,4 +48,27 @@ public Config readConfigFiles() { .map(Configs::from) .toArray(Config[]::new)); } + + public boolean dumpConfig(Config config, PrintStream dumpTo) { + if (!dumpConfig) { + return false; + } + + Map> toOutput = new TreeMap<>(); + for (String section : config.getSectionNames()) { + if (section.isEmpty() || IGNORED_SECTIONS.contains(section)) { + continue; + } + + config.getOptions(section).forEach(option -> + config.get(section, option).ifPresent(value -> + toOutput.computeIfAbsent(section, ignored -> new TreeMap<>()).put(option, value) + ) + ); + } + + dumpTo.print(new Json().toJson(toOutput)); + + return true; + } } diff --git a/java/server/src/org/openqa/selenium/grid/server/HelpFlags.java b/java/server/src/org/openqa/selenium/grid/server/HelpFlags.java index 14bda1ff2200d..b7109cf4056f3 100644 --- a/java/server/src/org/openqa/selenium/grid/server/HelpFlags.java +++ b/java/server/src/org/openqa/selenium/grid/server/HelpFlags.java @@ -30,16 +30,12 @@ public class HelpFlags { - private static final ImmutableSet IGNORED_SECTIONS = ImmutableSet.of("java", "lc", "term"); @Parameter(names = {"-h", "-help", "--help", "/?"}, help = true, hidden = true) private boolean help; @Parameter(names = "--version", description = "Displays the version and exits.") private boolean version; - @Parameter(names = "--dump-config", description = "Dump the config of the server as JSON.", hidden = true) - private boolean dumpConfig; - public boolean displayHelp(JCommander commander, PrintStream outputTo) { if (version) { BuildInfo info = new BuildInfo(); @@ -60,27 +56,4 @@ public boolean displayHelp(JCommander commander, PrintStream outputTo) { return false; } - - public boolean dumpConfig(Config config, PrintStream dumpTo) { - if (!dumpConfig) { - return false; - } - - Map> toOutput = new TreeMap<>(); - for (String section : config.getSectionNames()) { - if (section.isEmpty() || IGNORED_SECTIONS.contains(section)) { - continue; - } - - config.getOptions(section).forEach(option -> - config.get(section, option).ifPresent(value -> - toOutput.computeIfAbsent(section, ignored -> new TreeMap<>()).put(option, value) - ) - ); - } - - dumpTo.print(new Json().toJson(toOutput)); - - return true; - } }