Examples of ProcessedCommand


Examples of org.infinispan.cli.commands.ProcessedCommand

@Test(groups="functional", testName="cli.shell.ProcessedCommandTest")
public class ProcessedCommandTest {

   public void testArgumentParsing() {
      ProcessedCommand pc = new ProcessedCommand("cmd abc");
      assert "cmd".equals(pc.getCommand());

      assert pc.getArguments().size()==1;

      assert "abc".equals(pc.getArguments().get(0).getValue());
   }
View Full Code Here

Examples of org.infinispan.cli.commands.ProcessedCommand

      assert "abc".equals(pc.getArguments().get(0).getValue());
   }

   public void testQuotedArgumentParsing() {
      ProcessedCommand pc = new ProcessedCommand("cmd \"abc\" \"def\"");
      assert "cmd".equals(pc.getCommand());

      assert pc.getArguments().size()==2;

      assert "abc".equals(pc.getArguments().get(0).getValue());
      assert "def".equals(pc.getArguments().get(1).getValue());
   }
View Full Code Here

Examples of org.infinispan.cli.commands.ProcessedCommand

      assert "abc".equals(pc.getArguments().get(0).getValue());
      assert "def".equals(pc.getArguments().get(1).getValue());
   }

   public void testMixedArgumentParsing() {
      ProcessedCommand pc = new ProcessedCommand("cmd \"abc\" 'def' ghi");
      assert "cmd".equals(pc.getCommand());

      assert pc.getArguments().size()==3;

      assert "abc".equals(pc.getArguments().get(0).getValue());
      assert "def".equals(pc.getArguments().get(1).getValue());
      assert "ghi".equals(pc.getArguments().get(2).getValue());
   }
View Full Code Here

Examples of org.infinispan.cli.commands.ProcessedCommand

      assert "def".equals(pc.getArguments().get(1).getValue());
      assert "ghi".equals(pc.getArguments().get(2).getValue());
   }

   public void testNoArguments() {
      ProcessedCommand pc = new ProcessedCommand("cmd ");
      assert "cmd".equals(pc.getCommand());

      assert pc.getArguments().size()==0;

      assert pc.isCommandComplete();
   }
View Full Code Here

Examples of org.infinispan.cli.commands.ProcessedCommand

      } catch (Exception e) {
      }
   }

   private void execute(final String line) {
      ProcessedCommand parsed = new ProcessedCommand(line);
      Command command = context.getCommandRegistry().getCommand(parsed.getCommand());
      if (command != null) {
         command.execute(context, parsed);
      } else {
         context.error("Command " + parsed.getCommand() + " unknown or not available");
      }
   }
View Full Code Here

Examples of org.infinispan.cli.commands.ProcessedCommand

            if(command.isAvailable(context)) {
               candidates.add(name);
            }
         }
      } else {
         ProcessedCommand procCmd = new ProcessedCommand(buffer, op.getCursor());
         if(!procCmd.isCommandComplete()) {
            // A possibly incomplete command in the buffer, return the commands that match
            for(String name : context.getCommandRegistry().getCommandNames()) {
               Command command = context.getCommandRegistry().getCommand(name);
               if(command.isAvailable(context) && name.startsWith(procCmd.getCommand())) {
                  candidates.add(name);
               }
            }
         } else {
            Command command = context.getCommandRegistry().getCommand(procCmd.getCommand());
            if(command.isAvailable(context)) {
               op.setOffset(op.getCursor());
               for(Argument arg : procCmd.getArguments()) {
                  if(arg.getOffset()<op.getCursor()) {
                     op.setOffset(arg.getOffset());
                  } else {
                     break;
                  }
               }
               addPrefixMatches(procCmd.getCurrentArgument(), command.getOptions(), candidates);
               command.complete(context, procCmd, candidates);
            }
         }
      }
      Collections.sort(candidates);
View Full Code Here

Examples of org.jboss.aesh.cl.internal.ProcessedCommand

    }

    public ProcessedCommand generateParameter() throws CommandLineParserException {
        if(name == null || name.length() < 1)
            throw new CommandLineParserException("The parameter name must be defined");
        return  new ProcessedCommand(name, description, validator, argument, options);
    }
View Full Code Here

Examples of org.jboss.aesh.cl.internal.ProcessedCommand

*/
public class AeshExample {

    public static void main(String[] args) throws CommandLineParserException {

        ProcessedCommand fooCommand = new CommandBuilder()
                .name("foo")
                .description("fooing")
                .addOption(new OptionBuilder()
                        .name("bar")
                        .addDefaultValue("en 1 0")
View Full Code Here

Examples of org.jboss.aesh.cl.internal.ProcessedCommand

    public static CommandLineParser generateCommandLineParser(Class clazz) throws CommandLineParserException {
        CommandDefinition command = (CommandDefinition) clazz.getAnnotation(CommandDefinition.class);
        if(command == null)
            throw new CommandLineParserException("Commands must be annotated with @CommandDefinition");

        ProcessedCommand processedCommand = new ProcessedCommand(command.name(), command.description(), command.validator());

        for(Field field : clazz.getDeclaredFields()) {
            Option o;
            OptionGroup og;
            OptionList ol;
            Arguments a;
            if((o = field.getAnnotation(Option.class)) != null) {
                OptionType optionType;
                if(o.hasValue())
                    optionType = OptionType.NORMAL;
                else
                    optionType = OptionType.BOOLEAN;
                if(o.name() == null || o.name().length() < 1) {
                    processedCommand.addOption(o.shortName(), field.getName(), o.description(),
                            o.argument(), o.required(), ',', o.defaultValue(),
                            field.getType(), field.getName(), optionType, o.converter(),
                            o.completer(), o.validator(), o.activator(), o.renderer(), o.overrideRequired());
                }
                else {
                    processedCommand.addOption(o.shortName(), o.name(), o.description(),
                            o.argument(), o.required(), ',', o.defaultValue(),
                            field.getType(), field.getName(), optionType, o.converter(),
                            o.completer(), o.validator(), o.activator(), o.renderer(), o.overrideRequired());
                }

            }
            else if((ol = field.getAnnotation(OptionList.class)) != null) {
                if(!Collection.class.isAssignableFrom(field.getType()))
                    throw new CommandLineParserException("OptionGroup field must be instance of Collection");
                Class type = Object.class;
                if(field.getGenericType() != null) {
                    ParameterizedType listType = (ParameterizedType) field.getGenericType();
                    type = (Class) listType.getActualTypeArguments()[0];
                }
                if(ol.name() == null || ol.name().length() < 1) {
                    processedCommand.addOption(ol.shortName(), field.getName(), ol.description(), "",
                            ol.required(), ol.valueSeparator(), ol.defaultValue(), type, field.getName(), OptionType.LIST,
                            ol.converter(), ol.completer(), ol.validator(), ol.activator(), ol.renderer());
                }
                else {
                    processedCommand.addOption(ol.shortName(), ol.name(), ol.description(), "",
                            ol.required(), ol.valueSeparator(), ol.defaultValue(), type, field.getName(), OptionType.LIST,
                            ol.converter(), ol.completer(), ol.validator(), ol.activator(), ol.renderer());
                }
            }
            else if((og = field.getAnnotation(OptionGroup.class)) != null) {
                if(!Map.class.isAssignableFrom(field.getType()))
                    throw new CommandLineParserException("OptionGroup field must be instance of Map");
                Class type = Object.class;
                if(field.getGenericType() != null) {
                    ParameterizedType listType = (ParameterizedType) field.getGenericType();
                    type = (Class) listType.getActualTypeArguments()[1];
                }
                if(og.name() == null || og.name().length() < 1) {
                    processedCommand.addOption(og.shortName(), field.getName(), og.description(),
                            "", og.required(), ',', og.defaultValue(), type, field.getName(), OptionType.GROUP,
                            og.converter(), og.completer(), og.validator(), og.activator(), og.renderer());
                }
                else {
                    processedCommand.addOption(og.shortName(), og.name(), og.description(),
                            "", og.required(), ',', og.defaultValue(), type, field.getName(), OptionType.GROUP,
                            og.converter(), og.completer(), og.validator(), og.activator(), og.renderer());
                }
            }

            else if((a = field.getAnnotation(Arguments.class)) != null) {
                if(!Collection.class.isAssignableFrom(field.getType()))
                    throw new CommandLineParserException("Arguments field must be instance of Collection");
                Class type = Object.class;
                if(field.getGenericType() != null) {
                    ParameterizedType listType = (ParameterizedType) field.getGenericType();
                    type = (Class) listType.getActualTypeArguments()[0];
                }
                processedCommand.setArgument(
                        new ProcessedOption('\u0000',"", a.description(), "", false, a.valueSeparator(),
                                a.defaultValue(), type, field.getName(), OptionType.ARGUMENT, a.converter(),
                                a.completer(), a.validator(), null, null));
            }
        }
View Full Code Here

Examples of org.jboss.aesh.cl.internal.ProcessedCommand

*/
public class AeshExample {

    public static void main(String[] args) throws CommandLineParserException {

        ProcessedCommand fooCommand = new CommandBuilder()
                .name("foo")
                .description("fooing")
                .addOption(new OptionBuilder()
                        .name("bar")
                        .addDefaultValue("en 1 0")
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.