A - The command of their business logicpublic interface Command<A>
Command = Command.Mapping or Command.Parser
Constructors: Command.mapping(), Command.argument()
This commands:
/label concrete <string>
/label map a
/label map b <string>
can be represented:
interface MyCommand {
record Concrete(String s) implements MyCommand {}
class A implements MyCommand {}
record B(String s) implements MyCommand {}
}
Command.mapping(
pair("concrete", Command.argument(Concrete::new, strArg),
pair("map", Command.mapping(
pair("a", Command.argument(A::new),
pair("b", Command.argument(B::new, strArg)
)
)
Please note that the MyCommand is a sum type in other word such an enum with their individual fields, also called sealed class in Kotlin.
Command.Mapping,
Command.Parser| Modifier and Type | Interface and Description |
|---|---|
static class |
Command.Mapping<A>
Represents an abstract command with key-value pairs.
|
static class |
Command.Parser<A>
Represents a concrete command with type-safe arguments.
|
| Modifier and Type | Method and Description |
|---|---|
static <T,A,B> Command.Parser<T> |
argument(java.util.function.BiFunction<? super A,? super B,? extends T> f,
Argument<A> argA,
Argument<B> argB) |
static <T,A> Command.Parser<T> |
argument(java.util.function.Function<? super A,? extends T> f,
Argument<A> argument) |
static <T,A,B,C> Command.Parser<T> |
argument(Function3<? super A,? super B,? super C,? extends T> f,
Argument<A> argA,
Argument<B> argB,
Argument<C> argC) |
static <T,A,B,C,D> |
argument(Function4<? super A,? super B,? super C,? super D,? extends T> f,
Argument<A> argA,
Argument<B> argB,
Argument<C> argC,
Argument<D> argD) |
static <T,A,B,C,D,E> |
argument(Function5<? super A,? super B,? super C,? super D,? super E,? extends T> f,
Argument<A> argA,
Argument<B> argB,
Argument<C> argC,
Argument<D> argD,
Argument<E> argE) |
static <T,A,B,C,D,E,F> |
argument(Function6<? super A,? super B,? super C,? super D,? super E,? super F,? extends T> f,
Argument<A> argA,
Argument<B> argB,
Argument<C> argC,
Argument<D> argD,
Argument<E> argE,
Argument<F> argF) |
static <T,A,B,C,D,E,F,G> |
argument(Function7<? super A,? super B,? super C,? super D,? super E,? super F,? super G,? extends T> f,
Argument<A> argA,
Argument<B> argB,
Argument<C> argC,
Argument<D> argD,
Argument<E> argE,
Argument<F> argF,
Argument<G> argG) |
static <T> Command.Parser<T> |
argument(java.util.function.Supplier<T> f) |
static <A> java.util.List<java.util.Map.Entry<java.util.List<java.lang.String>,Command<A>>> |
getEntries(Command<A> cmd)
Make flatten commands.
|
<B> Command<B> |
map(java.util.function.Function<? super A,? extends B> f) |
static <A> Command.Mapping<A> |
mapping(Tuple2<java.lang.String,Command<? extends A>>... entries) |
static <K,V> Tuple2<K,V> |
pair(K key,
V value) |
static <A> Either<CommandFailure<A>,CommandSuccess<A>> |
parse(java.lang.String[] args,
Command<A> command) |
static <A> java.util.Optional<A> |
parseO(java.lang.String[] args,
Command<A> command) |
static <A> Either<CommandFailure<A>,CommandSuccess<A>> |
parseWithIndex(int index,
java.lang.String[] args,
Command<A> command) |
static <A> Command.Parser<A> |
present(A value) |
static <A> CommandTabResult<A> |
tabComplete(java.lang.String[] args,
Command<A> command) |
static <A> CommandTabResult<A> |
tabCompleteWithIndex(int index,
java.lang.String[] args,
Command<A> command) |
@SafeVarargs static <A> Command.Mapping<A> mapping(Tuple2<java.lang.String,Command<? extends A>>... entries)
static <A> Command.Parser<A> present(A value)
static <T> Command.Parser<T> argument(java.util.function.Supplier<T> f)
static <T,A> Command.Parser<T> argument(java.util.function.Function<? super A,? extends T> f, Argument<A> argument)
static <T,A,B> Command.Parser<T> argument(java.util.function.BiFunction<? super A,? super B,? extends T> f, Argument<A> argA, Argument<B> argB)
static <T,A,B,C> Command.Parser<T> argument(Function3<? super A,? super B,? super C,? extends T> f, Argument<A> argA, Argument<B> argB, Argument<C> argC)
static <T,A,B,C,D> Command.Parser<T> argument(Function4<? super A,? super B,? super C,? super D,? extends T> f, Argument<A> argA, Argument<B> argB, Argument<C> argC, Argument<D> argD)
static <T,A,B,C,D,E> Command.Parser<T> argument(Function5<? super A,? super B,? super C,? super D,? super E,? extends T> f, Argument<A> argA, Argument<B> argB, Argument<C> argC, Argument<D> argD, Argument<E> argE)
static <T,A,B,C,D,E,F> Command.Parser<T> argument(Function6<? super A,? super B,? super C,? super D,? super E,? super F,? extends T> f, Argument<A> argA, Argument<B> argB, Argument<C> argC, Argument<D> argD, Argument<E> argE, Argument<F> argF)
static <T,A,B,C,D,E,F,G> Command.Parser<T> argument(Function7<? super A,? super B,? super C,? super D,? super E,? super F,? super G,? extends T> f, Argument<A> argA, Argument<B> argB, Argument<C> argC, Argument<D> argD, Argument<E> argE, Argument<F> argF, Argument<G> argG)
static <K,V> Tuple2<K,V> pair(K key, V value)
static <A> Either<CommandFailure<A>,CommandSuccess<A>> parse(java.lang.String[] args, Command<A> command)
static <A> java.util.Optional<A> parseO(java.lang.String[] args,
Command<A> command)
static <A> Either<CommandFailure<A>,CommandSuccess<A>> parseWithIndex(int index, java.lang.String[] args, Command<A> command)
static <A> CommandTabResult<A> tabComplete(java.lang.String[] args, Command<A> command)
static <A> CommandTabResult<A> tabCompleteWithIndex(int index, java.lang.String[] args, Command<A> command)
static <A> java.util.List<java.util.Map.Entry<java.util.List<java.lang.String>,Command<A>>> getEntries(Command<A> cmd)
Example input:
{
a: {
a: cmdA,
b: cmdB
}
}
result:
[
(["a", "a"], cmdA),
(["a", "b"], cmdB),
...
]
A - the command of their business logiccmd - the node