Skip to content

Restore support for command grouping at class level in 4.0 #1266

@ThomasVitale

Description

@ThomasVitale

In Spring Shell 3.4, it was possible to define all commands belonging to the same group in the same class, and specify group information only once.

Example in 3.4:

@Command(command = "image build", group = "Image")
public class ImageBuildCommands {

    @Command(command = "buildpacks", description = "Build a container image using Buildpacks.")
    public void buildpacks() {
        ...
    }

    @Command(command = "dockerfile", description = "Build a container image using Dockerfile.")
    public void dockerfile() {
        ...
    }
    
}

Now, in Spring Shell 4.0, the @Command annotation cannot be assigned to a class anymore. It was indeed confusing to have such an annotation available at class level, but it was useful for configuring groups information.

Example in 4.0:

@Component
public class ImageBuildCommands {

    @Command(name = { "image", "build", "buildpacks" }, description = "Build a container image using Buildpacks.", group = "Image")
    public void buildpacks() {
        ...
    }

    @Command(name = { "image", "build", "dockerfile" }, description = "Build a container image using Dockerfile.", group = "Image")
    public void dockerfile() {
        ...
    }
    
}

Notice how I had to duplicate the group = "Image" attribute for each command in the group. Furthermore, I have to duplicate the parent commands for each command in the group: name = { "image", "build", "..." }. And things become even more verbose when attributes like alias are used, requiring duplication of the parent alias commands for each command in the group.

How about introducing a @CommandGroup annotation to restore some of the functionality in 3.4? Otherwise, currently in 4.0, things become very verbose and error-prone.

I'm available to help with a potential PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions