Ignore:
Timestamp:
08/28/12 13:33:23 (12 years ago)
Author:
sherbold
Message:
  • modified Command.help(): the help now returns a string with its usage instead of writing directly to the console
  • modified listCommands: now writes the help string of each command instead of just the name; this way, the parameters are displayed directly
  • moved listCommands from quest-ui-core to java-utils
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/java-utils/src/main/java/de/ugoe/cs/util/console/CommandExecuter.java

    r661 r664  
    1010import java.util.ArrayList; 
    1111import java.util.Arrays; 
     12import java.util.Collections; 
     13import java.util.Comparator; 
    1214import java.util.Enumeration; 
    1315import java.util.List; 
     
    138140            } 
    139141            catch (InvalidParameterException e) { 
    140                 cmd.help(); 
     142                Console.println("Usage: " + cmd.help()); 
    141143            } 
    142144        } 
     
    181183     * @return an array containing the names of the available commands. 
    182184     */ 
    183     public String[] getAvailableCommands() { 
    184         List<String> commands = new ArrayList<String>(); 
     185    public Command[] getAvailableCommands() { 
     186        List<Command> commands = new ArrayList<Command>(); 
    185187        List<String> packages = new ArrayList<String>(); 
    186188        packages.addAll(commandPackageList); 
     
    251253        } 
    252254         
     255        Collections.sort(classNames, new Comparator<String>() { 
     256            @Override 
     257            public int compare(String arg1, String arg2) { 
     258                String str1 = arg1.substring(arg1.lastIndexOf('.') + cmdPrefix.length() + 1); 
     259                String str2 = arg2.substring(arg2.lastIndexOf('.') + cmdPrefix.length() + 1); 
     260                return str1.compareTo(str2); 
     261            } 
     262             
     263        }); 
    253264        for (String className : classNames) { 
    254265            String commandStr = 
     
    261272                // class may still be inner classes. Therefore load the command, to 
    262273                // see if it is really available and a command. 
    263                 if (loadCMD(className) != null) { 
    264                     commands.add(commandStr); 
     274                Command cmd = loadCMD(className); 
     275                if (cmd != null) { 
     276                    commands.add(cmd); 
    265277                } 
    266278            } 
    267279        } 
    268280         
    269         String[] commandArray = commands.toArray(new String[commands.size()]); 
    270         Arrays.sort(commandArray); 
     281        Command[] commandArray = commands.toArray(new Command[commands.size()]); 
    271282        return commandArray; 
    272283    } 
Note: See TracChangeset for help on using the changeset viewer.