Skip to content

Add support for multiple non-interactive commands #372

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

Merged

Conversation

onobc
Copy link
Contributor

@onobc onobc commented Feb 18, 2022

Also:

  • Rename ThemeResolver bean to avoid clash w/ Spring Boot registered ThemeResolver
  • Move shell runner precedence to public static field to allow extension/access

This was needed to support spring.shell.commandFile option in SCDF shell. I originally implemented it in SCDF by creating a separate NonInteractiveShellRunner. However, its cleaner to simply support N commands here and let the commandfile->commands come in via customizer in SCDF (see here).

Also:
* Rename ThemeResolver bean to avoid clash w/ Spring Boot registered ThemeResolver
* Move shell runner precedence to public static field to allow extension/access
@@ -33,12 +33,12 @@
public ThemeRegistry themeRegistry(ObjectProvider<Theme> themes) {
ThemeRegistry registry = new ThemeRegistry();
registry.register(Theme.of("default", ThemeSettings.themeSettings()));
themes.orderedStream().forEachOrdered(theme -> registry.register(theme));
themes.orderedStream().forEachOrdered(registry::register);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[UNRELATED] Suggestion from IDEA (I agreed w/ it 😸 )

return registry;
}

@Bean
public ThemeResolver themeResolver(ThemeRegistry themeRegistry, SpringShellProperties properties) {
public ThemeResolver shellThemeResolver(ThemeRegistry themeRegistry, SpringShellProperties properties) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was clashing w/ the non-shell Spring MVC theme resolver bean in SB.

* The precedence at which this runner is ordered by the DefaultApplicationRunner - which also controls
* the order it is consulted on the ability to handle the current shell.
*/
public static final int PRECEDENCE = InteractiveShellRunner.PRECEDENCE - 50;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposed the order so that extenders can easily put other runners in front of/behind of a particular runner w/o knowing the core relation runner order relations


public NonInteractiveShellRunner(Shell shell, ShellContext shellContext) {
this.shell = shell;
this.shellContext = shellContext;
this.lineParser = new DefaultParser();
this.commandsFromInputArgs = (args) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change we took ApplicationArguments and created a single command out of it where each word in the command is one of the source args.

With this change the default is to take the ApplicationArguments and create a single command STRING out of it. It then in turn gets broken into words via the single ParseLineInput/Provider.

This allows extenders to pass in list of string commands such as:

history --file foo.txt
task create --force --name blah
....

@jvalkeal
Copy link
Contributor

thx, lgtm

@jvalkeal jvalkeal merged commit 5f447aa into spring-projects:main Feb 21, 2022
jvalkeal added a commit that referenced this pull request Feb 22, 2022
- Fix issue when empty args resulted runner to
  think it should handle this scenario effectively
  hijacking interactive mode.
- This bug were added by previous rework on #372
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants