[ 
https://issues.apache.org/jira/browse/KARAF-7554?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17606741#comment-17606741
 ] 

ASF GitHub Bot commented on KARAF-7554:
---------------------------------------

awrb commented on code in PR #1624:
URL: https://github.com/apache/karaf/pull/1624#discussion_r974620384


##########
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:
   I wanted the completer to work if there are multiple versions of a single 
feature available, but sadly `versions` is always a singleton here. In 
`FeatureReq` the latest version is returned:
   ```
       public Stream<Feature> getMatchingFeatures(Map<String, Map<String, 
Feature>> allFeatures) {
           Pattern pattern = Pattern.compile(name);
           Function<String, Optional<Feature>> func = featureName -> {
               Feature matchingFeature = null;
               if (pattern.matcher(featureName).matches()) {
                   Map<String, Feature> versions = allFeatures.get(featureName);
                   matchingFeature = getLatestFeature(versions, versionRange);
               }
               return Optional.ofNullable(matchingFeature);
           };
           return 
allFeatures.keySet().stream().map(func).filter(Optional::isPresent).map(Optional::get);
       }
   ```
   It does not seem possible to get all versions via `FeaturesService`
   





> 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)

Reply via email to