Skip to content

Argument information is not output at all when using the help command #1344

@bagelben

Description

@bagelben

The background to this issue is us migrating our application from Spring Boot 4 from 3.5, and along with that, moving to Spring Shell 4. Specifically Spring Boot 4.0.5 and Spring Shell 4.0.2

We have a number of commands which are similar, but I will include one of the simpler ones for reference:

In Spring Shell 3 our command was defined as follows:

@Command(command = "queue-depth, description = "Shows the number of messages on the specified queue", group = "Queue Depth")
    public String queueDepth(@Option(required = true, description = "Name of the Queue, or 'all' to display all queues", longNames = "queue-name") final String queueName )  {

        // Logic Goes here
    }

In Spring Shell 3 any Option defined can be actually be provided as an argument. This means that either of the following usages are logically equivalent

queue-depth queueName
queue-depth --queue-name queueName

We have historically relied on this before because most users would tend to use the command without providing the long option.

Now it seems like in version 4 this behaviour has deliberately removed in favour of having completely separated Options and Arguments as concepts. If there is any way of recreating the old behaviour it would be good to know. It would definitely be the most convenient for our purposes, as otherwise we will have to break one of the 2 ways of executing the command. If there is no way to achieve this we will have to migrate our Options to be Arguments, as that is our most common usage.

Now here comes the problem. Using Options is self-documenting. e.g. when we define an Option and provide a description, the help command will automatically populate it. So that the running the command help queue-depth would output the following useful output

 help queue-depth
NAME
        queue-depth - Shows the number of messages on the specified queue

SYNOPSIS
        queue-depth [--queue-name String]  --help

OPTIONS
        --queue-name String
        Name of the Queue, or 'all' to display all queues
        [Mandatory]

        --help or -h
        help for queue-depth
        [Optional]

Side note - it looks like the current behaviour only shows mandatory options in square brackets, and optional values are not in brackets. This feels like it is the opposite of what the behaviour should be. Although this seems to have always been the case.

Now if I was to migrate to Arguments instead of options - the following: @Argument(index = 0, description = "Name of the Queue, or 'all' to display all queues") final String queueName - the help would output the following:

 help queue-depth
NAME
        queue-depth - Shows the number of messages on the specified queue

SYNOPSIS
        queue-depth  --help

OPTIONS
        --help or -h
        help for queue-depth
        [Optional]

Which does not even mention that the command has arguments. The description element of the annotation seems to be completely ignored.

In addition there seems to be no way of making arguments mandatory, so we would have to add that validation ourselves.

One other thing I have noticed while gathering this evidence is that running queue-depth --help or queue-depth -h no longer seems to work. It now outputs an empty line. Whereas in the previous version we were using (which admittedly was 3.1.4) it worked fine

Metadata

Metadata

Assignees

No one assigned

    Labels

    status/need-triageTeam needs to triage and take a first look

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions