Skip to content

Abort on ambiguous subcommand names#629

Closed
dcantah wants to merge 1 commit into
apple:mainfrom
dcantah:disallow-same-cmdname
Closed

Abort on ambiguous subcommand names#629
dcantah wants to merge 1 commit into
apple:mainfrom
dcantah:disallow-same-cmdname

Conversation

@dcantah

@dcantah dcantah commented Apr 4, 2024

Copy link
Copy Markdown
Contributor

Currently it's possible to have two commands with the same _commandName by mixing a combination of the automatic command name generation based on the type name, and explicit use of CommandConfiguration's commandName parameter. For example, if we edit the math examples Add command to have a commandName of "multiply" this is allowed currently:

./.build/debug/math multiply 2 3
5

The behavior today is whatever subcommand is registered in the tree first is what will resolve for that command. So, Multiply in this example is permanently shadowed.

This change just makes sure there's no occurence of this happening in any level of the tree of potential subcommands, and if so we'll abort early.

Note

I can't imagine this happens too often, but the detection logic will also be useful to verify clashing aliases+subcommands for this change as well #627.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

@dcantah dcantah mentioned this pull request Apr 4, 2024
4 tasks
Comment thread Sources/ArgumentParser/Utilities/Tree.swift Outdated
Currently it's possible to have two commands with the same _commandName
by mixing a combination of the automatic command name generation based on
the type name, and explicit use of `CommandConfiguration`'s commandName
parameter. For example, if we edit the math examples `Add` command to
have a commandName of "multiply" this is allowed currently:

```
./.build/debug/math multiply 2 3
5
```

The behavior today is whatever subcommand is registered in the tree first
is what will resolve for that command. So, `Multiply` in this example is
permanently shadowed.

This change just makes sure there's no occurence of this happening in any
level of the tree of potential subcommands, and if so we'll abort early.
@dcantah dcantah force-pushed the disallow-same-cmdname branch from 1d3e481 to 241162e Compare April 4, 2024 11:53
@dcantah

dcantah commented Apr 11, 2024

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@dcantah

dcantah commented Apr 22, 2024

Copy link
Copy Markdown
Contributor Author

Gentle ping on this 😆. I'll start with this change as #627 can feed from it.

@dcantah

dcantah commented May 2, 2024

Copy link
Copy Markdown
Contributor Author

Let me draft this until I have time to fix up the way we validate this

@dcantah dcantah marked this pull request as draft May 2, 2024 22:02
@dcantah

dcantah commented May 31, 2024

Copy link
Copy Markdown
Contributor Author

Closing this as adding some validations here seems very tricky, if we do want this I'm glad to brainstorm with someone

@dcantah dcantah closed this May 31, 2024
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

Successfully merging this pull request may close these issues.

2 participants