Duplicate `len(args) == 2` branch makes `mountpoint:info` command unreachable
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:
Build and run Glance.
Execute:
glance mountpoint:info
- 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 <pwd>works (handled by the first branch).mountpoint:info <path>never reaches its handler, because the first branch'selsereturnsunknownCommandErrfirst.
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:infocommand 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.
Source: glanceapp/glance