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

CommandRegistration.Builder with lambdas #1142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -750,41 +750,90 @@ public interface Builder {
*/
OptionSpec withOption();

/**
* Define an option what this command should user for. Can be used multiple
* times.
*
* @param customizer the option spec consumer
* @return option spec for chaining
*/
Builder withOption(Consumer<OptionSpec> customizer);

/**
* Define a target what this command should execute
*
* @return target spec for chaining
*/
TargetSpec withTarget();

/**
* Define a target what this command should execute
*
* @param customizer the target spec consumer
* @return target spec for chaining
*/
Builder withTarget(Consumer<TargetSpec> customizer);

/**
* Define an alias what this command should execute
*
* @return alias spec for chaining
*/
AliasSpec withAlias();

/**
* Define an alias what this command should execute
*
* @param customizer the alias spec consumer
* @return alias spec for chaining
*/
Builder withAlias(Consumer<AliasSpec> customizer);

/**
* Define an exit code what this command should execute
*
* @return exit code spec for chaining
*/
ExitCodeSpec withExitCode();

/**
* Define an exit code what this command should execute
*
* @param customizer the exit code spec consumer
* @return exit code spec for chaining
*/
Builder withExitCode(Consumer<ExitCodeSpec> customizer);

/**
* Define an error handling what this command should use
*
* @return error handling spec for chaining
*/
ErrorHandlingSpec withErrorHandling();

/**
* Define an error handling what this command should use
*
* @param customizer the error handling spec consumer
* @return error handling spec for chaining
*/
Builder withErrorHandling(Consumer<ErrorHandlingSpec> customizer);

/**
* Define help options what this command should use.
*
* @return help options spec for chaining
*/
HelpOptionsSpec withHelpOptions();

/**
* Define help options what this command should use.
*
* @param customizer the help options spec consumer
* @return help options spec for chaining
*/
Builder withHelpOptions(Consumer<HelpOptionsSpec> customizer);

/**
* Builds a {@link CommandRegistration}.
*
Expand Down Expand Up @@ -1407,34 +1456,74 @@ public OptionSpec withOption() {
return spec;
}

@Override
public Builder withOption(Consumer<OptionSpec> customizer) {
DefaultOptionSpec spec = new DefaultOptionSpec(this);
customizer.accept(spec);
optionSpecs.add(spec);
return this;
}

@Override
public TargetSpec withTarget() {
DefaultTargetSpec spec = new DefaultTargetSpec(this);
targetSpec = spec;
return spec;
}

@Override
public Builder withTarget(Consumer<TargetSpec> customizer) {
DefaultTargetSpec spec = new DefaultTargetSpec(this);
customizer.accept(spec);
targetSpec = spec;
return this;
}

@Override
public AliasSpec withAlias() {
DefaultAliasSpec spec = new DefaultAliasSpec(this);
this.aliasSpecs.add(spec);
return spec;
}

@Override
public Builder withAlias(Consumer<AliasSpec> customizer) {
DefaultAliasSpec spec = new DefaultAliasSpec(this);
customizer.accept(spec);
this.aliasSpecs.add(spec);
return this;
}

@Override
public ExitCodeSpec withExitCode() {
DefaultExitCodeSpec spec = new DefaultExitCodeSpec(this);
this.exitCodeSpec = spec;
return spec;
}

@Override
public Builder withExitCode(Consumer<ExitCodeSpec> customizer) {
DefaultExitCodeSpec spec = new DefaultExitCodeSpec(this);
customizer.accept(spec);
this.exitCodeSpec = spec;
return this;
}

@Override
public ErrorHandlingSpec withErrorHandling() {
DefaultErrorHandlingSpec spec = new DefaultErrorHandlingSpec(this);
this.errorHandlingSpec = spec;
return spec;
}

@Override
public Builder withErrorHandling(Consumer<ErrorHandlingSpec> customizer) {
DefaultErrorHandlingSpec spec = new DefaultErrorHandlingSpec(this);
customizer.accept(spec);
this.errorHandlingSpec = spec;
return this;
}

@Override
public HelpOptionsSpec withHelpOptions() {
if (this.helpOptionsSpec == null) {
Expand All @@ -1443,6 +1532,15 @@ public HelpOptionsSpec withHelpOptions() {
return this.helpOptionsSpec;
}

@Override
public Builder withHelpOptions(Consumer<HelpOptionsSpec> customizer) {
if (this.helpOptionsSpec == null) {
this.helpOptionsSpec = new DefaultHelpOptionsSpec(this);
}
customizer.accept(this.helpOptionsSpec);
return this;
}

@Override
public CommandRegistration build() {
Assert.notNull(commands, "command cannot be empty");
Expand Down
Loading