diff options
author | Luck <git@lucko.me> | 2018-12-31 18:33:11 +0000 |
---|---|---|
committer | Luck <git@lucko.me> | 2018-12-31 18:33:11 +0000 |
commit | 3be95dbe1305b176fc8c25d636454c159390fae7 (patch) | |
tree | 5b6a1ebfaabb721e3d72b9c821ccc080efb13dd7 /spark-common/src/main/java | |
parent | f1b0085e2917e393e09ab77f37734846a131f68e (diff) | |
download | spark-3be95dbe1305b176fc8c25d636454c159390fae7.tar.gz spark-3be95dbe1305b176fc8c25d636454c159390fae7.tar.bz2 spark-3be95dbe1305b176fc8c25d636454c159390fae7.zip |
Add tab completion for newly added arguments
Diffstat (limited to 'spark-common/src/main/java')
3 files changed, 15 insertions, 12 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java index 405b3d3..6f748fb 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/MemoryModule.java @@ -23,6 +23,7 @@ package me.lucko.spark.common.command.modules; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; +import me.lucko.spark.common.command.tabcomplete.TabCompleter; import me.lucko.spark.memory.HeapDump; import me.lucko.spark.memory.HeapDumpSummary; @@ -72,6 +73,7 @@ public class MemoryModule<S> implements CommandModule<S> { } }); }) + .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--run-gc-before")) .build() ); @@ -109,6 +111,7 @@ public class MemoryModule<S> implements CommandModule<S> { platform.sendPrefixedMessage("&bHeap dump written to: " + file.toString()); }); }) + .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--run-gc-before", "--include-non-live")) .build() ); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java index d0513ab..3ad8909 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/modules/TickMonitoringModule.java @@ -23,14 +23,10 @@ package me.lucko.spark.common.command.modules; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.command.Command; import me.lucko.spark.common.command.CommandModule; -import me.lucko.spark.common.command.tabcomplete.CompletionSupplier; import me.lucko.spark.common.command.tabcomplete.TabCompleter; import me.lucko.spark.monitor.TickMonitor; import me.lucko.spark.sampler.TickCounter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.function.Consumer; public class TickMonitoringModule<S> implements CommandModule<S> { @@ -64,14 +60,7 @@ public class TickMonitoringModule<S> implements CommandModule<S> { platform.sendPrefixedMessage("&7Tick monitor disabled."); } }) - .tabCompleter((platform, sender, arguments) -> { - List<String> opts = new ArrayList<>(Arrays.asList("--threshold", "--without-gc")); - opts.removeAll(arguments); - - return TabCompleter.create() - .from(0, CompletionSupplier.startsWith(opts)) - .complete(arguments); - }) + .tabCompleter((platform, sender, arguments) -> TabCompleter.completeForOpts(arguments, "--threshold", "--without-gc")) .build() ); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java b/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java index f8774b2..d2b2622 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java @@ -27,6 +27,8 @@ package me.lucko.spark.common.command.tabcomplete; import com.google.common.base.Preconditions; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,6 +42,15 @@ public class TabCompleter { return new TabCompleter(); } + public static List<String> completeForOpts(List<String> args, String... options) { + List<String> opts = new ArrayList<>(Arrays.asList(options)); + opts.removeAll(args); + + return TabCompleter.create() + .from(0, CompletionSupplier.startsWith(opts)) + .complete(args); + } + private final Map<Integer, CompletionSupplier> suppliers = new HashMap<>(); private int from = Integer.MAX_VALUE; |