Skip to content

Conflicting alias', either branch or command alias', are not flagged accordingly #49

@FrankRay78

Description

@FrankRay78

Background
Currently, when a command alias conflicts with the name of another command, an exception is thrown to notify the user.

For example, the following command configuration:

        // Given
        var app = new CommandApp();
        app.Configure(config =>
        {
            config.PropagateExceptions();

            config.AddCommand<GreeterCommand>("echo");
            config.AddCommand<DogCommand>("dog").WithAlias("echo");
        });

        // When
        var result = app.Run(new[]
        {
            "echo",
        });

Throws the following when run:

Spectre.Console.Cli.CommandConfigurationException : The alias 'echo' for 'dog' conflicts with another command.

nb. The CommandModelValidator class is responsible for performing the check:

image

Information

  • OS: Windows
  • Version: commit SHA 04610cf492296277c415dc6a48d19a43178bec12

Describe the bug
When configuring multiple commands with the same alias, no error is thrown and the command which has been configured first is attempted to be run.

To Reproduce
The following code, which executes successfully, illustrates this behaviour:

        // Given
        var app = new CommandAppTester();
        app.Configure(config =>
        {
            config.PropagateExceptions();

            config.AddCommand<GreeterCommand>("echo").WithAlias("a");
            config.AddCommand<DogCommand>("dog").WithAlias("a");
        });

        // When
        var result = app.Run(new[]
        {
            "a",
        });

        // Then
        result.Output.ShouldBe("Hello World");

Expected behavior
The user should be informed that an alias cannot be used twice, at least at the same level of the command hierarchy

Additional context
Now that alias' can be added to command branches (spectreconsole/spectre.console#411), the accepted solution should also address when duplicate alias' occur across multiple commands/multiple branches/multiple commands and branches, at the same level


Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions