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

Make CommandRegistration.Builder matching with new SecurityFilterChain builder format #1127

Open
heavynimbus opened this issue Aug 23, 2024 · 1 comment
Labels
type/enhancement Is an enhancement request

Comments

@heavynimbus
Copy link

Hi,
I think CommandRegistration.Builder can be upgraded by following new SecurityFilterChain's builder usage from Spring Security

@Bean
public CommandRegistration myCommand() {
  return CommandRegistration.builder()
    .command("my-command")
    .withOption()
    .longName("option1")
    .required()
    .type(String.class)
    .and()
    .withOption()
    .longName("option1")
    .required()
    .type(String.class)
    .and()
    .withTarget()
    .consumer(ctx -> ctx.getTerminal().writer().println("Hello World"))
    .and()
    .build();
}

Could became:

@Bean
public CommandRegistration myCommand() {
  return CommandRegistration.builder()
    .command("my-command")
    .withOption(optionCustomizer -> 
      optionCustomizer.longName("option1")
        .required()
        .type(String.class)
    )
    .withOption(optionCustomizer -> 
      optionCustomizer.longName("option2")
        .required()
        .type(String.class)
    )
    .withTarget(targetCustomizer ->
      targetCustomizer.consumer(ctx -> ctx.getTerminal().writer().println("Hello World"))
    )
    .build();
}

This could be done for withOption, withTarget, withAlias, withErrorHandling, withHelpOption and withExitCode

I think this makes for more readable code and allows for better indentation for automated formatters

Thank's for reading :)

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Aug 23, 2024
@jvalkeal
Copy link
Contributor

Without looking into details this sounds like a good idea.

While you don't need to chain "dsl type javaconfig" together order to get better programmatic access I've always disliked that approach as config then starts to look a bit cluttered. Taking idea from a Spring Security for lambda style makes that part more clean.

@jvalkeal jvalkeal added type/enhancement Is an enhancement request and removed status/need-triage Team needs to triage and take a first look labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Is an enhancement request
Projects
None yet
Development

No branches or pull requests

2 participants