Sunday 31 January 2021

Spring Shell: Register command with multiple alias names

In my previous post, I explained how to change the command name using ‘key’ attribute. You can even set multiple keys to the same method using ‘key’ attribute.

 

Example

@ShellComponent(value = "Multiple names to the same commands")
public class MultipleAliases {

    @ShellMethod(value = "Commands to welcome user", key = { "welcome", "wish", "say-hello" })
    public String sayHello(String name) {
        return "Good Morning " + name + "!!!!!";
    }
}

 

Now you can wish the user using either of below command names.

a.   welcome

b.   wish

c.    say-hello

 

shell:>say-hello "Krishna"
Good Morning Krishna!!!!!
shell:>
shell:>welcome "Krishna"
Good Morning Krishna!!!!!
shell:>
shell:>wish "Krishna"
Good Morning Krishna!!!!!
shell:>

 

You can download complete application from this link.

https://github.com/harikrishna553/springboot/tree/master/shell/hello-world

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment