Trouble with 4.0.0 #1259
Replies: 14 comments 4 replies
-
|
I've been having some of the same issues. I registered some of them:
I would suggest raising dedicated GitHub issues for each problem to make it easier to handle them. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the detailed feedback, @gturner834 ! And thank you @ThomasVitale for the follow up on this. I will reply in separate comments so we can elaborate on each topic with discussion threads. Everything you can do with Spring Shell v3 is possible with v4. Most issues reported here seem to be related to undocumented changes in the migration guide (apologies for the confusion, I will update the guide asap). I will also explain the reasoning behind each change and how to handle things in v4. I understand that major releases can cause some migration effort/issues, but I believe v4 includes many necessary changes that are required for the long term sustainability and maintenance of the project. As with every overhaul, I am expecting some bumps and corner cases that were missed in the GA, but I am committed to release 4.0.1 (planned for January 21st) and 4.0.2 to fix major issues if any as soon as possible and to help our users migrate their apps to v4. Please note that v4.0 is a foundational release, which I believe provides a strong base compared to previous versions to maintain Spring Shell in the future, and I am open to adapt v4 and try to align it with v3 when it makes sense. |
Beta Was this translation helpful? Give feedback.
-
Following the unix philosophy of doing one thing at a time and doing it well, it does not make sense for a shell application to be interactive and non-interactive at the same time. The fact that it was possible to be in both modes at the same time in v3 resulted in several problems:
In v4, you have to choose which mode to be in from the beginning and all these problems just disappear by design/construction. I updated the migration guide with a section about this change: Shell interactivity changes |
Beta Was this translation helpful? Give feedback.
-
One of the main themes of v4 is API/Annotation simplification and we really don't need a separate annotation for command scanning as we already have |
Beta Was this translation helpful? Give feedback.
-
With v3, You would also need to build one these for every option, so the "boilerplate" is equally the same, it's just now centralized (which is better than scattered). However, I am not sure why it is an issue to build a completer for every command, that's part of the command customisation (each command has its own completer, availability provider, etc). The one big issue though of having a completer per option (apart from having to define many beans for a single command), is that providing cross options completion is just impossible. Here is an example: enum Gender {
MALE, FEMALE
}
@Command(
name = "hello",
description = "Say hello to a given name",
group = "Greetings",
help = "A command that greets the user with 'Hello ${name}!'. Usage: hello [-g | --gender]=<gender> [-n | --name]=<name>",
completionProvider = "helloCompletionProvider")
public void sayHello(
@Option(shortName = 'n', longName = "name", description = "the name of the person to greet", defaultValue = "World") String name,
@Option(shortName = 'g', longName = "gender", description = "the gender of the person to greet") Gender gender) {
String prefix = switch (gender) {
case MALE -> "Mr. ";
case FEMALE -> "Ms. ";
};
System.out.println("Hello " + prefix + name + "!");
}
@Bean
public CompletionProvider helloCompletionProvider() {
// if gender is female, suggest "Alice" and "Eve", otherwise suggest "Bob" and "Charlie"
return completionContext ->
{
CommandOption commandOption = completionContext.getCommandOption();
// check option name and value and return appropriate proposals
return List.of();
};
}As you can see, providing completion for names based on the gender is possible with this approach compared to v3. I updated the migration guide with a section about this: Command completion
To be honest, I was not aware of that in v3. But we can improve this in the default completer of v4: if the current option is an enum, the completer should return the enum's values. I created #1282 to align things with v3. |
Beta Was this translation helpful? Give feedback.
-
This is mentioned in the migration guide here.
This is not accurate, sub-commands are still supported, and the Spring PetClinic CLI app is a working sample with sub-commands. Now, regarding the duplication in the command prefix (in the example you shared, you are concatenating command names but the import org.springframework.shell.core.command.annotation.Command;
import org.springframework.stereotype.Component;
@Component
public class GitHubCommands {
private static final String GROUP = "Github commands";
private static final String ROOT_COMMAND = "github";
private boolean connected = false;
@Command(name = {ROOT_COMMAND, "login"}, description = "Login to GitHub", group = GROUP)
public void login() {
// handle authentication logic here
connected = true;
}
@Command(name = {ROOT_COMMAND, "logout"}, description = "Logout from GitHub", group = GROUP)
public void logout() {
// handle logout logic here
connected = false;
}
}I really don't see the need for using the same annotation at two different levels to inherit common attributes, especially an Spring Shell v2 has a Last thing, it'a amazing how no one is complaining about not being able to inherit common attributes for related Spring import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
//@Configuration(autowireCandidate = false) // Why isn't this a problem even if not possible?
public class RelatedBeans {
public static final boolean AUTOWIRE_CANDIDATE = false;
@Bean(autowireCandidate = AUTOWIRE_CANDIDATE)
public String bean1() {
return "bean1";
}
@Bean(autowireCandidate = AUTOWIRE_CANDIDATE)
public String bean2() {
return "bean2";
}
} |
Beta Was this translation helpful? Give feedback.
-
This was reported in #1245 and is planned for 4.0.1 |
Beta Was this translation helpful? Give feedback.
-
This is really one of the "superfluous" features of Spring Shell 3 (with its Please take a look at #1220 where I explain the rationale behind this simplification with some examples of modern and well-established tools that have a single value for short/long option names. However, I noticed that this was missing from the migration guide, so I added a note about it here: Command options. |
Beta Was this translation helpful? Give feedback.
-
This is indeed a regression. I created to #1285 to track it and planned it for the upcoming 4.0.1
This was reported in #1280. The change was documented (see the Debug Mode section), but not mentioned in the migration guide, my bad.. I just added a section about it here. The main reason of this change is that the stacktrace command requires global mutable state to keep the stacktrace of the last command and there is no good place for this global state. Similar to many popular CLI frameworks/tools, Spring Shell 4 introduce a debug mode, which when enabled, prints the stack trace of the last command right away instead of the user asking for it right after. So the idea is that you configure the shell in debug mode once (like for example running Maven with -X flag) and have the stack trace of every error, instead of having to type stacktrace every time an error occurs. |
Beta Was this translation helpful? Give feedback.
-
Reported in #1271 and planned for 4.0.1 |
Beta Was this translation helpful? Give feedback.
-
Another superfluous / confusing feature. A label/tag would be useful in ordering, grouping, querying things (a good example of label usage is in k8s pod labelling, where one could query for pods having a specific label) but none of this is used here. It's only used for the help string. In the same spirit of simplifying things, an option should have a single short/long name. The migration guide was updated accordingly. |
Beta Was this translation helpful? Give feedback.
-
Similar to help, I think this was a regression of the removal of the template engine (ST4) from the |
Beta Was this translation helpful? Give feedback.
-
That was really one of the areas of the framework where I was astonished many times both in terms of feature design/usability and by the code behind the testing APIs.. There is no point in repeating what I have said in #1234 (please see related issues as well), but you basically have two options:
Please let me know if you need support in migrating your tests and I will be happy to help. |
Beta Was this translation helpful? Give feedback.
-
Coming from Spring Shell 3, I can understand that because Spring Shell 4 is quite different from v3. But for someone new to Spring Shell, things in v4 are:
So all in all, and while I was expecting some bumps and corner cases in this 4.0 GA, I strongly believe that Spring Shell 4 (once stabilized in 4.0.1, 4.0.2) will be foundational release that provides a strong base for the long term sustainability of the project.
As mentioned previously, most of these issues where unfortunately undocumented in the migration guide (apologies for the confusion, but now I updated the guide accordingly) and valid ones will be fixed in 4.0.1 planned for January 21st, so it is up to you to migrate now of wait for 4.0.1. After all, nothing is really blocking as far as I can tell: all issues are either valid minor bugs, or improvements to make things work as in v3 where it makes sense. I hope I answered all your questions/ concerns, but please let me know in comments/threads if you need help on migrating to v4. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Brief description of our projects:
Originally:
Storage, custom Airflow integration, etc.
outdated version of Hibernate.
Goal:
interactive mode (completion, help, history, colored output, etc.) is really great!
Progress:
Issues with 4.0.0
Interactive and non-interactive modes are now mutually exclusive.
spring.shell.interactive.enabled = true, running the jar with any arguments automatically engaged non-interactive behavior, giving best of both worlds: without arguments = interactive, with arguments = non-interactive.@CommandScanwas removed and the replacementCommandRegistryAutoConfigurationwhich only scans from the@SpringBootApplicationdeclaring package.list").
registerAnnotatedCommands.@OptionValueswas removed, replaced with@Command-level declaration, causing a lot of boilerplate.@Command( command = ["restart"], description = "Restart a job" ) fun restart( @Option( longNames = ["jobName"], shortNames = ['j'], required = false, description = "Name of the job to restart", label = "JOB_NAME", arity = ZERO_OR_ONE ) @OptionValues(provider = [JobNameCompletionProvider.BEAN_NAME]) jobName: String? = null, ) {}@Command( name = ["batch restart"], description = "Restart a job", completionProvider = "batchCommandRestartCompletionProvider" ) fun restart( @Option( shortName = 'j', longName = "jobName", description = "Name of the job to restart", ) jobName: String? = null, ) {} @Bean fun batchCommandRestartCompletionProvider(): CompositeCompletionProvider { TODO("Need to build one of these for every command, with hard-coded parameter names") }@OptionValueswith no provider on enums was working great before, and will now have to constructEnumCompletionProviderfor each command.@Commandis no longer applicable to classes (methods only), hierarchy/sub-commands no longer supported.Optional parameters spam warning messages.
@Optionno longer supports alternative/alias longNames (array vs. single value).Exception handling in interactive mode does not report cause, and
stacktracecommand no longer exists.stacktracecommand.Regression with
help@Optionhas removedlabelproperty pertaining tohelp(e.g. seeDATE,NAME,EMAIL, etc. in 3.4 example above).Regression with
versionscriptfor the purpose of printing build information in our Airflow logs (people liked it, "Look what Spring Shell does out of the box!").@ShellTestoverhaul looks like it'll be helpful, but I'm still working through the above issues, unable to execute tests just yet...Quite a bit of a set back. It seems like Spring Shell is in flux. Should I hold off on the 4.0.0 upgrade, wait and see if any of the above issues are resolved first?
Beta Was this translation helpful? Give feedback.
All reactions