/**
 * Copyright (C) 2011, FuseSource Corp.  All rights reserved.
 * http://fusesource.com
 *
 * The software in this package is published under the terms of the
 * CDDL license a copy of which has been included with this distribution
 * in the license.txt file.
 */
package org.fusesource.fabric.zookeeper.commands;

import org.apache.felix.gogo.commands.Argument;
import org.apache.felix.gogo.commands.Command;
import org.apache.felix.gogo.commands.Option;

@Command(name = "list", scope = "zk", description = "List a node's children")
public class List extends ZooKeeperCommandSupport {

    @Option(name = "-r", aliases = {"--recursive"}, description = "Display children recursively")
    boolean recursive;

    @Argument(description = "Path of the node to list", required = true)
    String path;

    @Override
    protected Object doExecute() throws Exception {
        display(path);
        return null;
    }

    protected void display(String path) throws Exception {
        java.util.List<String> children = getZooKeeper().getChildren(path);
        for (String child : children) {
            String cp = path.endsWith("/") ? path + child : path + "/" + child;
            System.out.println(cp);
            if (recursive) {
                display(cp);
            }
        }
    }
}

@@ -584,16 +584,96 @@
 port %7B%0A%0A
+    @Argument(description = %22Path of the node to list%22)%0A    String path = %22/%22;%0A%0A
     @Opt
@@ -787,99 +787,137 @@
 sive
-;%0A%0A    @Argument(description = %22Path of the node to list%22, required = true)%0A    String path
+ = false;%0A%0A    @Option(name=%22-d%22, aliases=%7B%22--display%22%7D, description=%22Display a node's value if set%22)%0A    boolean display = false
 ;%0A%0A 
@@ -1050,32 +1050,40 @@
 ted 
-void display(String p
+java.util.List%3CString%3E getP
 ath
+s(
 ) th
@@ -1111,196 +1111,537 @@
     
-java.util.List%3CString%3E children = getZooKeeper().getChildren(path);%0A        for (String child : children) %7B%0A            
+if (recursive) %7B%0A            return getZooKeeper().getAllChildren(path);%0A        %7D else %7B%0A            return getZooKeeper().getChildren(path);%0A        %7D%0A    %7D%0A%0A    protected void display(String path) throws Exception %7B%0A        java.util.List%3CString%3E paths = getPaths();%0A%0A        for(
 String 
-c
 p 
-=
+:
  path
-.endsWith(%22/%22) ? path + child : path + %22/%22 + child;%0A
+s) %7B%0A            if (display) %7B%0A                byte%5B%5D data = getZooKeeper().getData(p);%0A                if (data != null) %7B%0A                    System.out.printf(%22%25s = %25s%5Cn%22, p, new String(data));%0A                %7D else %7B%0A        
     
@@ -1667,17 +1667,16 @@
 println(
-c
 p);%0A    
@@ -1687,50 +1687,70 @@
     
+    
-if (recursive) %7B%0A                display(c
+%7D%0A            %7D else %7B%0A                System.out.println(
 p);%0A

Improve list command to show values, to use / by default, etc