Duplicate `len(args) == 2` branch makes `mountpoint:info` command unreachable
- Dominant language
- Go
- Stars
- 37.1k
- Forks
- 1.5k
- Avg merge
- 1h 11m
- Merged PRs (30d)
- 1
Description
### Summary
In `parseCliOptions`, there are two consecutive `else if len(args) == 2` branches. The second one is dead code and can never be executed, which makes the `mountpoint:info` command effectively unusable — it always falls through to the first `len(args) == 2` branch and returns `unknown command`.
### Affected Code
```
} else if len(args) == 2 {
if args[0] == "password:hash" {
intent = cliIntentPasswordHash
} else {
return nil, unknownCommandErr
}
} else if len(args) == 2 { // ← unreachable: same condition as above
if args[0] == "mountpoint:info" {
intent = cliIntentMountpointInfo
} else {
return nil, unknownCommandErr
}
} else {
return nil, unknownCommandErr
}
```
### Steps to reproduce:
1. Build and run Glance.
2. Execute:
```
glance mountpoint:info
```
3. Observe the result.
### Expected Behavior
The `mountpoint:info` command should be recognized and `cliMountpointInfo` should be invoked with the given path (as advertised in the usage output: `unknown command: mountpoint:info`).
### Root Cause
The second else if len(args) == 2 has exactly the same condition as the first one. Since the first branch already matches whenever len(args) == 2, the second branch is unreachable dead code. As a result:
- `password:hash ` works (handled by the first branch).
- `mountpoint:info ` never reaches its handler, because the first branch's `else` returns `unknownCommandErr` first.
-
### Suggested Fix
Merge the two branches into a `single len(args) == 2` block:
```
} else if len(args) == 2 {
if args[0] == "password:hash" {
intent = cliIntentPasswordHash
} else if args[0] == "mountpoint:info" {
intent = cliIntentMountpointInfo
} else {
return nil, unknownCommandErr
}
} else {
return nil, unknownCommandErr
}
```
### Impact
- The `mountpoint:info` command documented in the usage/help text is completely non-functional.
- Any user relying on this command gets a misleading "unknown command" error instead of the intended output.
### Additional Notes
- Worth adding a small test covering argument parsing for each documented command to catch this kind of unreachable-branch regression in the future.
- I'm happy to open a PR with the fix if that would be helpful.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating parseCliOptions and inspect the consecutive len(args) == 2 branches shown in the issue. Verify the argument-parsing tests or add coverage for password:hash and mountpoint:info, then run the relevant Go tests. Done means mountpoint:info reaches cliMountpointInfo instead of returning unknownCommandErr.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100