Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate argument newBuilder methods and add builder methods to align with newer arguments #419

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Cloud allows for commands to be defined using builder patterns, like this:
manager.command(
manager.commandBuilder("command", Description.of("Test cloud command using a builder"), "alias")
.argument(StringArgument.of("input"))
.argument(IntegerArgument.<CommandSender>newBuilder("number").withMin(1).withMax(100).build())
.argument(IntegerArgument.<CommandSender>builder("number").withMin(1).withMax(100).build())
.handler(context -> {
String input = context.get("input");
int number = context.get("number");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ public void deleteRootCommand(final @NonNull String rootCommand) throws CloudCap
* @return Flag builder
*/
public CommandFlag.@NonNull Builder<Void> flagBuilder(final @NonNull String name) {
return CommandFlag.newBuilder(name);
return CommandFlag.builder(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,27 @@ private CommandFlag(
this.mode = Objects.requireNonNull(mode, "mode cannot be null");
}

/**
* Create a new {@link Builder}.
*
* @param name flag name
* @return new {@link Builder}
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
public static @NonNull Builder<Void> builder(final @NonNull String name) {
return new Builder<>(name);
}

/**
* Create a new flag builder
*
* @param name Flag name
* @return Flag builder
* @deprecated prefer {@link #builder(String)}
*/
@API(status = API.Status.DEPRECATED, since = "1.8.0")
@Deprecated
public static @NonNull Builder<Void> newBuilder(final @NonNull String name) {
return new Builder<>(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,31 @@ private BooleanArgument(
this.liberal = liberal;
}

/**
* Create a new {@link Builder}.
*
* @param name argument name
* @param <C> sender type
* @return new {@link Builder}
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new Builder<>(name);
}

/**
* Create a new builder
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
* @deprecated prefer {@link #builder(String)}
*/
@API(status = API.Status.DEPRECATED, since = "1.8.0")
@Deprecated
public static <C> @NonNull Builder<C> newBuilder(final @NonNull String name) {
return new Builder<>(name);
return builder(name);
}

/**
Expand All @@ -82,7 +98,7 @@ private BooleanArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Boolean> of(final @NonNull String name) {
return BooleanArgument.<C>newBuilder(name).asRequired().build();
return BooleanArgument.<C>builder(name).asRequired().build();
}

/**
Expand All @@ -93,7 +109,7 @@ private BooleanArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Boolean> optional(final @NonNull String name) {
return BooleanArgument.<C>newBuilder(name).asOptional().build();
return BooleanArgument.<C>builder(name).asOptional().build();
}

/**
Expand All @@ -108,7 +124,7 @@ private BooleanArgument(
final @NonNull String name,
final boolean defaultBoolean
) {
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(Boolean.toString(defaultBoolean)).build();
return BooleanArgument.<C>builder(name).asOptionalWithDefault(Boolean.toString(defaultBoolean)).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,28 @@ private ByteArgument(
/**
* Create a new {@link Builder}.
*
* @param name argument name
* @param <C> sender type
* @return new {@link Builder}
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new Builder<>(name);
}

/**
* Create a new builder
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
* @deprecated prefer {@link #builder(String)}
*/
@API(status = API.Status.DEPRECATED, since = "1.8.0")
@Deprecated
public static <C> @NonNull Builder<C> newBuilder(final @NonNull String name) {
return new Builder<>(name);
return builder(name);
}

/**
Expand All @@ -80,7 +96,7 @@ private ByteArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Byte> of(final @NonNull String name) {
return ByteArgument.<C>newBuilder(name).asRequired().build();
return ByteArgument.<C>builder(name).asRequired().build();
}

/**
Expand All @@ -91,7 +107,7 @@ private ByteArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Byte> optional(final @NonNull String name) {
return ByteArgument.<C>newBuilder(name).asOptional().build();
return ByteArgument.<C>builder(name).asOptional().build();
}

/**
Expand All @@ -106,7 +122,7 @@ private ByteArgument(
final @NonNull String name,
final byte defaultNum
) {
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
return ByteArgument.<C>builder(name).asOptionalWithDefault(defaultNum).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,31 @@ private CharArgument(
super(required, name, new CharacterParser<>(), defaultValue, Character.class, suggestionsProvider, defaultDescription);
}

/**
* Create a new {@link Builder}.
*
* @param name argument name
* @param <C> sender type
* @return new {@link Builder}
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new Builder<>(name);
}

/**
* Create a new builder
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
* @deprecated prefer {@link #builder(String)}
*/
public static <C> CharArgument.@NonNull Builder<C> newBuilder(final @NonNull String name) {
return new CharArgument.Builder<>(name);
@API(status = API.Status.DEPRECATED, since = "1.8.0")
@Deprecated
public static <C> @NonNull Builder<C> newBuilder(final @NonNull String name) {
return builder(name);
}

/**
Expand All @@ -74,7 +90,7 @@ private CharArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Character> of(final @NonNull String name) {
return CharArgument.<C>newBuilder(name).asRequired().build();
return CharArgument.<C>builder(name).asRequired().build();
}

/**
Expand All @@ -85,7 +101,7 @@ private CharArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Character> optional(final @NonNull String name) {
return CharArgument.<C>newBuilder(name).asOptional().build();
return CharArgument.<C>builder(name).asOptional().build();
}

/**
Expand All @@ -100,7 +116,7 @@ private CharArgument(
final @NonNull String name,
final @NonNull String defaultNum
) {
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
return CharArgument.<C>builder(name).asOptionalWithDefault(defaultNum).build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,28 @@ private DoubleArgument(
/**
* Create a new {@link Builder}.
*
* @param name argument name
* @param <C> sender type
* @return new {@link Builder}
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
public static <C> @NonNull Builder<C> builder(final @NonNull String name) {
return new Builder<>(name);
}

/**
* Create a new builder
*
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
* @deprecated prefer {@link #builder(String)}
*/
@API(status = API.Status.DEPRECATED, since = "1.8.0")
@Deprecated
public static <C> @NonNull Builder<C> newBuilder(final @NonNull String name) {
return new Builder<>(name);
return builder(name);
}

/**
Expand All @@ -80,7 +96,7 @@ private DoubleArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Double> of(final @NonNull String name) {
return DoubleArgument.<C>newBuilder(name).asRequired().build();
return DoubleArgument.<C>builder(name).asRequired().build();
}

/**
Expand All @@ -91,7 +107,7 @@ private DoubleArgument(
* @return Created argument
*/
public static <C> @NonNull CommandArgument<C, Double> optional(final @NonNull String name) {
return DoubleArgument.<C>newBuilder(name).asOptional().build();
return DoubleArgument.<C>builder(name).asOptional().build();
}

/**
Expand All @@ -106,7 +122,7 @@ private DoubleArgument(
final @NonNull String name,
final double defaultNum
) {
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
return DoubleArgument.<C>builder(name).asOptionalWithDefault(defaultNum).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,41 @@ protected EnumArgument(
super(required, name, new EnumParser<>(enumClass), defaultValue, enumClass, suggestionsProvider, defaultDescription);
}

/**
* Create a new {@link Builder}.
*
* @param enumClass enum class
* @param name argument name
* @param <C> sender type
* @param <E> enum type
* @return new {@link Builder}
* @since 1.8.0
*/
@API(status = API.Status.STABLE, since = "1.8.0")
public static <C, E extends Enum<E>> @NonNull Builder<C, E> builder(
final @NonNull Class<E> enumClass,
final @NonNull String name
) {
return new Builder<>(name, enumClass);
}

/**
* Create a new builder
*
* @param enumClass enum class
* @param name Name of the argument
* @param enumClass Enum class
* @param <C> Command sender type
* @param <E> Enum type
* @param <E> enum type
* @return Created builder
* @deprecated prefer {@link #builder(Class, String)}
*/
public static <C, E extends Enum<E>> EnumArgument.@NonNull Builder<C, E> newBuilder(
@API(status = API.Status.DEPRECATED, since = "1.8.0")
@Deprecated
public static <C, E extends Enum<E>> @NonNull Builder<C, E> newBuilder(
final @NonNull Class<E> enumClass,
final @NonNull String name
) {
return new EnumArgument.Builder<>(name, enumClass);
return builder(enumClass, name);
}

/**
Expand All @@ -93,7 +114,7 @@ protected EnumArgument(
final @NonNull Class<E> enumClass,
final @NonNull String name
) {
return EnumArgument.<C, E>newBuilder(enumClass, name).asRequired().build();
return EnumArgument.<C, E>builder(enumClass, name).asRequired().build();
}

/**
Expand All @@ -109,7 +130,7 @@ protected EnumArgument(
final @NonNull Class<E> enumClass,
final @NonNull String name
) {
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptional().build();
return EnumArgument.<C, E>builder(enumClass, name).asOptional().build();
}

/**
Expand All @@ -127,7 +148,7 @@ protected EnumArgument(
final @NonNull String name,
final @NonNull E defaultValue
) {
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
return EnumArgument.<C, E>builder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
}


Expand Down
Loading