Skip to content

DynamicCommands does not work in 2.1.0-M5 #456

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

Closed
kidomine opened this issue Jul 12, 2022 · 2 comments
Closed

DynamicCommands does not work in 2.1.0-M5 #456

kidomine opened this issue Jul 12, 2022 · 2 comments

Comments

@kidomine
Copy link

kidomine commented Jul 12, 2022

I was playing with dynamic commands using the spring shell samples (see https://github.com/spring-projects/spring-shell/blob/main/spring-shell-samples/src/main/java/org/springframework/shell/samples/standard/DynamicCommands.java) and I noticed that I cannot get it to work.

Below is the sample output form this example, built directly from 2.1.0-M5 branch:

❯ java -jar .\spring-shell-samples-2.1.0-M5.jar
::
my-shell:>blow-up
Boom!
my-shell:>connect
my-shell:>authenticate --credentials sesame
my-shell:>blow-up
Boom!
my-shell:>
my-shell:>

I added some logs in the blowUp command to print connect and authenticate and below is the result:

❯ java -jar .\spring-shell-samples-2.1.0-M5.jar
::
shell:>blow-up
connected=false
authenticated=false
Boom!
shell:>connect
shell:>authenticate --credentials sesame
shell:>blow-up
connected=true
authenticated=true
Boom!
shell:>

It seems half of the issue is not reproducible in 2.1.0-M3. When the help command is executed, I get the following result for Dynamic Commands:

2.1.0-M3 2.1.0-M5
Dynamic Commands
       *authenticate: Authenticate with the system
       blow-up: Blow Everything up
       connect: Connect to the system
       disconnect: Disconnect from the system
        
Dynamic Commands
       disconnect: Disconnect from the system
       authenticate: Authenticate with the system
       blow-up: Blow Everything up
       connect: Connect to the system
        

Notice how there is an * in the authenticate for 2.1.0-M3 indicating that it is initially disabled. However, this is not the case for 2.1.0-M5 . Note that I haven't tested the behavior in 2.1.0-M4.

Executing authenticate in 2.1.0-M3 works as expected, i.e.:

my-shell:>authenticate
Command 'authenticate' exists but is not currently available because you are not connected
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.

Clarification for 2.1.0-M3:

By default, blowUp does not work properly in 2.1.0-M3. It turns out this is an error in the sample as there is no implementation for dangerousAvailability.
However, after adding implementation for dangerousAvailability, blowUp works as expected:

public Availability dangerousAvailability() {
        return connected && authenticated ? Availability.available()
                : Availability.unavailable("you failed to authenticate. Try 'sesame'.");
    }

Given this information, it appears that ShellMethodAvailability and xxxAvailability are both not respected in 2.1.0-M5.
It would be great if someone could have a look at this.

@jvalkeal
Copy link
Contributor

Did you try main or 2.1.0-RC1 as there was #423 which had fixes for dynamic commands.

@kidomine
Copy link
Author

I did not realize there was an RC1. I can confirm that the behavior is OK in 2.1.0-RC1.
Thank you!

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

No branches or pull requests

2 participants