Programmatic

In the programmatic model, CommandRegistration can be defined as a @Bean and it will be automatically registered.

@Bean
CommandRegistration commandRegistration() {
	return CommandRegistration.builder()
		.command("mycommand")
		.build();
}

If all your commands have something in common, an instance of a CommandRegistration.BuilderSupplier is created which can be autowired. Default implementation of this supplier returns a new builder so you don’t need to worry about its internal state.

Commands registered programmatically automatically add help options mentioned in Help Options.

If bean of this supplier type is defined then auto-configuration will back off giving you an option to redefine default functionality.

@Bean
CommandRegistration commandRegistration(CommandRegistration.BuilderSupplier builder) {
	return builder.get()
		.command("mycommand")
		.build();
}

CommandRegistrationCustomizer beans can be defined if you want to centrally modify builder instance given you by supplier mentioned above.

@Bean
CommandRegistrationCustomizer commandRegistrationCustomizerExample() {
	return builder -> {
		// customize instance of CommandRegistration.Builder
	};
}