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

Have Shell Play Nice With Spring Boot #34

Closed
kurron opened this Issue May 18, 2014 · 11 comments

Comments

Projects
None yet
9 participants
@kurron

kurron commented May 18, 2014

I've tried combining Spring Boot and Spring Shell because I liked how Spring Boot can create a nice self-contained executable JAR. What I found was that both projects create competing Spring contexts. I've tried a couple different hacks with less than satisfactory results. It would be nice if Spring Shell and Spring Boot were aware of each other so that we could write nice shell-based tools and get all the Spring Boot goodness as well.

@btiernay

This comment has been minimized.

btiernay commented Sep 27, 2014

Agreed. Im looking to do the same for the same reasons.

@dsyer

This comment has been minimized.

Member

dsyer commented Sep 29, 2014

What is it that is "nice" about Spring Shell that you can't do with Spring Boot (especially with the CLI)?

@btiernay

This comment has been minimized.

btiernay commented Sep 29, 2014

Well, for one isn't the Spring Boot CLI for developers, not end users of the applications built with Spring Boot? Secondly, if you are trying to build an application that has a shell as one of its primary interfaces, Spring Shell seems very appropriate if you are developing with Spring. My use case is building something like the mongo shell that has both a CLI and shell interface. For the CLI I'm using JCommander because it has very rich support (something that is missing in both Spring and Spring Boot). One of the commands was going to be "shell", which would drop me into a Spring Shell session. The integration point doesn't look very good since it wan't to take full control of the application context. Lastly, I considered using CRaSH but that seems to be more geared towards operational concerns and not primary users.

@dsyer

This comment has been minimized.

Member

dsyer commented Sep 29, 2014

Spring Boot CLI as it is packaged and distributed for Spring Boot is for developers, but it's just a fairly thin layer that we use to bootstrap pluggable commands, so it could be used (or bits could be extracted) to make your task easier.

If I understand correctly, Spring Boot CLI is much closer to what you need as a building block since it already is a CLI and a shell (whereas Spring Shell is just a shell as far as I know). Spring Boot CLI also has no opinion whatsoever about how to build an ApplicationContext so it won't get in your way at all there.

The Grails guys (cc @lhotari) are working on a command line / shell tool for Grails 3.0 as well, so it might be worth checking what they are doing too. I think it might even be based on Spring Boot, or at least contain some of the same code, so there is a good chance that we can extract a common framework for building such apps.

Is JCommander included with Spring Shell? We like JOpt in Spring Boot, and it seems pretty well suited to building a self-describing CLI, so maybe it's worth a look if you haven't tried it.

Agree that CRaSH is probably not the right vehicle.

@btiernay

This comment has been minimized.

btiernay commented Sep 29, 2014

Spring Boot CLI as it is packaged and distributed for Spring Boot is for developers, but it's just a fairly thin layer that we use to bootstrap pluggable commands, so it could be used (or bits could be extracted) to make your task easier.

Extracting the non-development aspects would be certainly welcomed. I would rather not pull in new dependencies like Groovy, etc. if they are not used / required.

If I understand correctly, Spring Boot CLI is much closer to what you need as a building block since it already is a CLI and a shell (whereas Spring Shell is just a shell as far as I know). Spring Boot CLI also has no opinion whatsoever about how to build an ApplicationContext so it won't get in your way at all there.

That sounds great, although its not clear how things are bootstrapped looking at https://github.com/spring-projects/spring-boot/blob/master/spring-boot-cli/src/main/java/org/springframework/boot/cli/SpringCli.java . I don't see how I would integrate with a custom application context.

The Grails guys (cc @lhotari) are working on a command line / shell tool for Grails 3.0 as well, so it might be worth checking what they are doing too. I think it might even be based on Spring Boot, or at least contain some of the same code, so there is a good chance that we can extract a common framework for building such apps.

This would certainly be a win-win for all, so long as it could be made flexible, much like how boot is already.

Is JCommander included with Spring Shell? We like JOpt in Spring Boot, and it seems pretty well suited to building a self-describing CLI, so maybe it's worth a look if you haven't tried it.

Actually, I have had quite a bit of experience in this space. I've used about 4-5 different CLI libraries in Java and JCommander is by far the most versatile, flexible and easy to use. I really like how it is annotation based (think @ConfigurationProperties here), supports @file syntax (think curl), supports sub-commands (think git), etc. I used to use JOpt a few years back but seemed to fall short for more complex use cases. That and it seemed more programmatic than it needed to be. I suggest taking a look at JCommander which was written by the same guy who wrote TestNG (@cbeust).

And to answer your question, no it is not bundled with Spring Shell. Btw, this SO question is kinda related to this topic http://stackoverflow.com/questions/25194410/what-is-the-recommended-way-to-add-first-class-command-line-processing-to-spring

@dima767

This comment has been minimized.

dima767 commented Dec 18, 2014

Here's Grails shell (just for reference): https://github.com/grails/grails-core/tree/master/grails-shell

@hansvanbeneden

This comment has been minimized.

@jeffellin

This comment has been minimized.

jeffellin commented Sep 19, 2015

I have gotten this to work by hacking the BootStrap class a bit.

https://github.com/jeffellin/springshellwithboot

odrotbohm added a commit to spring-projects/spring-data-dev-tools that referenced this issue Nov 21, 2015

Significant Java 8 updates and Spring Boot integration.
Moved to Spring Boot 1.3 and leverage the new configuration properties mechanism (see GitProperties and IoProperties). Improved ArtifactVersion to be a better value object.

Introduced usage of Java 8's CompletableFuture to execute most of the Git operations in parallel. Started to use Lambdas where possible.

Git configuration is now supposed to be done using a application-local.properties (Git ignored) file containing the relevant properties (see readme). The test configuration now uses a separate workspace location and a Sample release train to make sure the integration tests run without interfering a local workspace.

Added train declaration for Hopper. Integrated BootShim (see [0], [1]) to run the shell on top of Spring Boot.

[0] https://github.com/jeffellin/springshellwithboot
[1] spring-projects/spring-shell#34
@kpb

This comment has been minimized.

kpb commented Jan 11, 2016

I would love this feature also - make it easy to bootstrap a spring-shell app with spring-boot. No shims or other hacks.

@linux-china

This comment has been minimized.

linux-china commented May 9, 2016

Based on @jeffellin code, I created a spring-boot-starter-shell to make spring shell with spring-boot easy. https://github.com/linux-china/spring-boot-starter-shell

@ericbottard

This comment has been minimized.

Member

ericbottard commented Aug 16, 2017

Closing as addressed for Shell 1 (see above). Spring Shell 2 plays nicely with Boot out of the box

@ericbottard ericbottard added the 1.x label Aug 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment