Skip to content

Commit 242ca57

Browse files
committed
enhance comments and do not optimize if results are != 1
1 parent 1ad8fca commit 242ca57

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cli/arguments/reference.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,25 @@ func ParseReference(arg string) (*Reference, error) {
8484
}
8585
ret.Architecture = toks[1]
8686

87-
// We try to optimize the search and help the user
87+
// Now that we have the required informations in `ret` we can
88+
// try to use core.GetPlatforms to optimize what the user typed
89+
// (by replacing the PackageName and Architecture in ret with the content of core.GetPlatform())
8890
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
8991
Instance: instance.CreateAndInit(),
9092
UpdatableOnly: false,
91-
All: true,
93+
All: true, // this is true because we want also the installable platforms
9294
})
95+
var found = 0
9396
for _, platform := range platforms {
9497
if strings.EqualFold(platform.GetId(), ret.PackageName+":"+ret.Architecture) {
9598
toks = strings.Split(platform.GetId(), ":")
96-
ret.PackageName = toks[0]
97-
ret.Architecture = toks[1]
98-
break // is it ok to stop at the first result?
99+
found++
99100
}
100101
}
101-
102+
// replace the returned Reference only if only one occurrence is found, otherwise leave it as is
103+
if found == 1 {
104+
ret.PackageName = toks[0]
105+
ret.Architecture = toks[1]
106+
}
102107
return ret, nil
103108
}

0 commit comments

Comments
 (0)