karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5759) Add an option to config:list to list only the PIDs
Date Sun, 17 Jun 2018 19:17:00 GMT

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

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

jbonofre closed pull request #528: [KARAF-5759] Add short option on config:list command
URL: https://github.com/apache/karaf/pull/528
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/config/src/main/java/org/apache/karaf/config/command/ListCommand.java b/config/src/main/java/org/apache/karaf/config/command/ListCommand.java
index dc041c9ba8..6d1e5d0f67 100644
--- a/config/src/main/java/org/apache/karaf/config/command/ListCommand.java
+++ b/config/src/main/java/org/apache/karaf/config/command/ListCommand.java
@@ -23,6 +23,7 @@
 
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.osgi.service.cm.Configuration;
 
@@ -30,6 +31,9 @@
 @Service
 public class ListCommand extends ConfigCommandSupport {
 
+    @Option(name = "-s", aliases = "--short", description = "Only list the PIDs, not the
properties", required = false, multiValued = false)
+    boolean shortOutput;
+
     @Argument(index = 0, name = "query", description = "Query in LDAP syntax. Example: \"(service.pid=org.apache.karaf.log)\"",
required = false, multiValued = false)
     String query;
 
@@ -41,23 +45,29 @@ protected Object doExecute() throws Exception {
             for (Configuration config : configs) {
                 sortedConfigs.put(config.getPid(), config);
             }
-            for (Configuration config : sortedConfigs.values()) {
-                System.out.println("----------------------------------------------------------------");
-                System.out.println("Pid:            " + config.getPid());
-                if (config.getFactoryPid() != null) {
-                    System.out.println("FactoryPid:     " + config.getFactoryPid());
+            if (shortOutput) {
+                for (Configuration config : sortedConfigs.values()) {
+                    System.out.println(config.getPid());
                 }
-                System.out.println("BundleLocation: " + config.getBundleLocation());
-                if (config.getProperties() != null) {
-                    System.out.println("Properties:");
-                    Dictionary props = config.getProperties();
-                    Map<String, Object> sortedProps = new TreeMap<>();
-                    for (Enumeration e = props.keys(); e.hasMoreElements();) {
-                        Object key = e.nextElement();
-                        sortedProps.put(key.toString(), props.get(key));
+            } else {
+                for (Configuration config : sortedConfigs.values()) {
+                    System.out.println("----------------------------------------------------------------");
+                    System.out.println("Pid:            " + config.getPid());
+                    if (config.getFactoryPid() != null) {
+                        System.out.println("FactoryPid:     " + config.getFactoryPid());
                     }
-                    for (Map.Entry<String, Object> entry : sortedProps.entrySet())
{
-                        System.out.println("   " + entry.getKey() + " = " + displayValue(entry.getValue()));
+                    System.out.println("BundleLocation: " + config.getBundleLocation());
+                    if (config.getProperties() != null) {
+                        System.out.println("Properties:");
+                        Dictionary props = config.getProperties();
+                        Map<String, Object> sortedProps = new TreeMap<>();
+                        for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
+                            Object key = e.nextElement();
+                            sortedProps.put(key.toString(), props.get(key));
+                        }
+                        for (Map.Entry<String, Object> entry : sortedProps.entrySet())
{
+                            System.out.println("   " + entry.getKey() + " = " + displayValue(entry.getValue()));
+                        }
                     }
                 }
             }
diff --git a/itests/test/src/test/java/org/apache/karaf/itests/ConfigTest.java b/itests/test/src/test/java/org/apache/karaf/itests/ConfigTest.java
index 4b24d6017a..63bf0f2120 100644
--- a/itests/test/src/test/java/org/apache/karaf/itests/ConfigTest.java
+++ b/itests/test/src/test/java/org/apache/karaf/itests/ConfigTest.java
@@ -45,6 +45,14 @@ public void listCommand() throws Exception {
         assertFalse(configListOutput.isEmpty());
     }
 
+    @Test
+    public void listShortCommand() throws Exception {
+        String configListOutput = executeCommand("config:list -s");
+        System.out.println(configListOutput);
+        assertFalse(configListOutput.isEmpty());
+        assertContains("org.apache.karaf.jaas\norg.apache.karaf.kar\n", configListOutput);
+    }
+
     @SuppressWarnings("unchecked")
     @Test
     public void configsViaMBean() throws Exception {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add an option to config:list to list only the PIDs
> --------------------------------------------------
>
>                 Key: KARAF-5759
>                 URL: https://issues.apache.org/jira/browse/KARAF-5759
>             Project: Karaf
>          Issue Type: Improvement
>          Components: karaf-config, karaf-shell
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: 4.1.6, 4.2.1
>
>
> {{config:list}} command gives by default the list of  PID with all properties in each
config. It's not easy to read and not convenient when looking for a specific PID. We can add
an option (like {{-s}} for {{--short}}) to only list the PID (not the properties).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message