[
https://issues.apache.org/jira/browse/KARAF-7554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17607915#comment-17607915
]
ASF GitHub Bot commented on KARAF-7554:
---------------------------------------
awrb commented on code in PR #1624:
URL: https://github.com/apache/karaf/pull/1624#discussion_r976823194
##########
features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureVersionCompleter.java:
##########
@@ -0,0 +1,41 @@
+package org.apache.karaf.features.command.completers;
+
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.support.completers.StringsCompleter;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class FeatureVersionCompleter implements Completer {
+
+ @Reference
+ private FeaturesService featuresService;
+
+ @Override
+ public int complete(Session session, CommandLine commandLine, List<String>
candidates) {
+ StringsCompleter delegate = new StringsCompleter();
+ String[] args = commandLine.getArguments();
+ // args look like this at this point: [feature:status, wrapper, '']
+ if (args.length >= 3) {
+ String featureArg = args[1];
+ try {
+ Feature[] features = featuresService.getFeatures(featureArg);
+ List<String> versions =
Arrays.stream(features).map(Feature::getVersion).collect(Collectors.toList());
+ delegate.getStrings().addAll(versions);
Review Comment:
```
private List<String> getAllVersionsOfFeature(String feature,
FeaturesService featuresService) throws Exception {
List<String> versions = new ArrayList<>();
for (Repository repo : featuresService.listRepositories()) {
for (Feature f : repo.getFeatures()) {
if (f.getName().equals(feature)) {
versions.add(f.getVersion());
}
}
}
return versions;
}
```
> Add feature:status command
> --------------------------
>
> Key: KARAF-7554
> URL: https://issues.apache.org/jira/browse/KARAF-7554
> Project: Karaf
> Issue Type: Sub-task
> Components: karaf
> Reporter: Aleksy Wróblewski
> Priority: Minor
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)