Examples of CommandParserContext


Examples of org.jboss.forge.shell.command.parser.CommandParserContext

   {
      CommandParser commandParser = new CompositeCommandParser(new NamedBooleanOptionParser(),
               new NamedValueOptionParser(), new NamedValueVarargsOptionParser(), new OrderedValueOptionParser(),
               new OrderedValueVarargsOptionParser(), new NullTokenOptionParser());

      CommandParserContext context = new CommandParserContext();
      Map<OptionMetadata, Object> valueMap = commandParser.parse(command, tokens, context)
               .getValueMap();

      for (String warning : context.getWarnings())
      {
         ShellMessages.info(shell, warning);
      }

      Object[] parameters = new Object[command.getOptions().size()];
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

      OptionMetadata option = state.getOption();
      if ((option != null) && (state.getCommandContext() != null))
      {

         CommandParserContext commandContext = state.getCommandContext();
         Map<OptionMetadata, Object> valueMap = commandContext.getValueMap();
         if (valueMap.isEmpty() || valueMap.containsKey(option))
         {
            if (option.hasCustomCompleter())
            {
               CommandCompleter completer = BeanManagerUtils.getContextualInstance(manager, option.getCompleterType());
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

      OptionMetadata option = state.getOption();
      if ((option != null) && (state.getCommandContext() != null))
      {

         CommandParserContext commandContext = state.getCommandContext();
         Map<OptionMetadata, Object> valueMap = commandContext.getValueMap();
         if (valueMap.isEmpty() || valueMap.containsKey(option))
         {
            if (option.hasCustomCompleter())
            {
               CommandCompleter completer = BeanManagerUtils.getContextualInstance(manager, option.getCompleterType());
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

   private void getOptionCandidates(final CommandMetadata command, final PluginCommandCompleterState state)
   {
      ArrayList<String> results = new ArrayList<String>();
      Queue<String> tokens = state.getTokens();
      CommandParserContext commandContext = commandParser.parse(state.getCommand(), tokens,
               new CommandParserContext());
      state.setCommandContext(commandContext);
      Map<OptionMetadata, Object> valueMap = commandContext.getValueMap();
      List<OptionMetadata> options = command.getOptions();

      if (tokens.isEmpty())
      {
         if (state.isFinalTokenComplete())
         {
            if ((commandContext.isEmpty() || commandContext.isLastOptionValued()))
            {
               for (OptionMetadata option : options)
               {
                  if (!valueMap.containsKey(option))
                  {
                     if (option.isNamed() && option.isRequired())
                     {
                        results.clear();
                        results.add("--" + option.getName() + " ");
                        break;
                     }
                     else if (option.isNamed())
                     {
                        results.add("--" + option.getName() + " ");
                     }
                     else if (!option.isNamed() && !option.isPipeOut() && !option.isPipeIn())
                     {
                        state.setOption(option);
                        break;
                     }
                  }
               }
            }
            else if (!commandContext.isEmpty() && !commandContext.isLastOptionValued())
            {
               state.setOption(commandContext.getLastParsed());
            }
         }
         else
         {
            if (!state.isFinalTokenComplete() && !commandContext.isEmpty())
            {
               state.setOption(commandContext.getLastParsed());

               if (commandContext.isLastOptionValued())
               {
                  state.getTokens().add(commandContext.getLastParsedToken());
               }
            }
         }
      }
      else
      {
         String finalToken = tokens.peek();
         int finalTokenIndex = state.getBuffer().lastIndexOf(finalToken);

         boolean tailOptionValued = true;
         boolean finalTokenIsValue = false;
         if (!finalToken.startsWith("-"))
         {
            finalTokenIsValue = true;
            finalTokenIndex = state.getIndex();
         }
         else
         {
            boolean shortOption = finalToken.matches("^-[^\\-]+$")
                     && (finalToken.length() > 1);
            finalToken = finalToken.replaceFirst("^[-]+", "");
            for (Entry<OptionMetadata, Object> entry : valueMap.entrySet())
            {
               OptionMetadata option = entry.getKey();
               if (entry.getValue() == null)
               {
                  tailOptionValued = false;
               }
               if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
                        finalToken)))
               {
                  state.setOption(option);
               }
            }

            if (tailOptionValued)
            {
               for (OptionMetadata option : options)
               {
                  if (option.isNamed())
                  {
                     if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
                              finalToken)) && valueMap.containsKey(option))
                     {
                        if (!state.isFinalTokenComplete())
                        {
                           results.add(" ");
                        }
                        break;
                     }
                     if (option.getName().startsWith(finalToken) && !valueMap.containsKey(option))
                     {
                        results.add("--" + option.getName() + " ");
                     }
                  }
               }
            }

            if (!results.isEmpty())
            {
               tokens.remove();
            }

            /*
             * If we haven't gotten any suggestions yet, then we just need to add everything we haven't seen yet. First
             * time - just the required options.
             */
            if (results.isEmpty() && tailOptionValued)
            {
               for (OptionMetadata option : options)
               {
                  if (option.isNamed() && !valueMap.containsKey(option))
                  {
                     if (option.isRequired() || state.isDuplicateBuffer())
                        results.add("--" + option.getName() + " ");
                  }
               }
            }

         }

         // add to state
         if (!state.isFinalTokenComplete() && finalTokenIsValue)
         {
            state.setOption(commandContext.getLastParsed());
            results.clear();
            if (state.isDuplicateBuffer())
            {
               // wait until the buffer remains the same until we append a space
               results.add(" ");
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

      OptionMetadata option = state.getOption();
      if ((option != null) && (state.getCommandContext() != null))
      {

         CommandParserContext commandContext = state.getCommandContext();
         Map<OptionMetadata, Object> valueMap = commandContext.getValueMap();
         if (valueMap.isEmpty() || valueMap.containsKey(option))
         {
            if (option.hasCustomCompleter())
            {
               CommandCompleter completer = BeanManagerUtils.getContextualInstance(manager, option.getCompleterType());
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

   private void getOptionCandidates(final CommandMetadata command, final PluginCommandCompleterState state)
   {
      ArrayList<String> results = new ArrayList<String>();
      Queue<String> tokens = state.getTokens();
      CommandParserContext context = new CommandParserContext();
      context.setCompleting(true);
      context.setFinalTokenComplete(state.isFinalTokenComplete());
      commandParser.parse(state.getCommand(), tokens,
               context);
      state.setCommandContext(context);
      Map<OptionMetadata, Object> valueMap = context.getValueMap();
      List<OptionMetadata> options = command.getOptions();

      if (tokens.isEmpty())
      {
         if (state.isFinalTokenComplete())
         {
            if ((context.isEmpty() || context.isLastOptionValued()))
            {
               for (OptionMetadata option : options)
               {
                  if (!valueMap.containsKey(option))
                  {
                     if (option.isNamed() && option.isRequired())
                     {
                        results.clear();
                        results.add("--" + option.getName() + " ");
                        break;
                     }
                     else if (option.isNamed())
                     {
                        results.add("--" + option.getName() + " ");
                     }
                     else if (!option.isNamed() && !option.isPipeOut() && !option.isPipeIn())
                     {
                        state.setOption(option);
                        break;
                     }
                  }
               }
            }
            else if (!context.isEmpty() && !context.isLastOptionValued())
            {
               state.setOption(context.getLastParsed());
            }
         }
         else
         {
            if (!state.isFinalTokenComplete() && !context.isEmpty())
            {
               state.setOption(context.getLastParsed());

               if (context.isLastOptionValued())
               {
                  state.getTokens().add(context.getLastParsedToken());
               }
            }
         }
      }
      else
      {
         String finalToken = tokens.peek();
         int finalTokenIndex = state.getBuffer().lastIndexOf(finalToken);

         boolean tailOptionValued = true;
         boolean finalTokenIsValue = false;
         if (!finalToken.startsWith("-"))
         {
            finalTokenIsValue = true;
            finalTokenIndex = state.getIndex();
         }
         else
         {
            boolean shortOption = finalToken.matches("^-[^\\-]+$")
                     && (finalToken.length() > 1);
            finalToken = finalToken.replaceFirst("^[-]+", "");
            for (Entry<OptionMetadata, Object> entry : valueMap.entrySet())
            {
               OptionMetadata option = entry.getKey();
               if (entry.getValue() == null)
               {
                  tailOptionValued = false;
               }
               if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
                        finalToken)))
               {
                  state.setOption(option);
               }
            }

            if (tailOptionValued)
            {
               for (OptionMetadata option : options)
               {
                  if (option.isNamed())
                  {
                     if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
                              finalToken)) && valueMap.containsKey(option))
                     {
                        if (!state.isFinalTokenComplete())
                        {
                           results.add(" ");
                        }
                        break;
                     }
                     if (option.getName().startsWith(finalToken) && !valueMap.containsKey(option))
                     {
                        results.add("--" + option.getName() + " ");
                     }
                  }
               }
            }

            if (!results.isEmpty())
            {
               tokens.remove();
            }

            /*
             * If we haven't gotten any suggestions yet, then we just need to add everything we haven't seen yet. First
             * time - just the required options.
             */
            if (results.isEmpty() && tailOptionValued)
            {
               for (OptionMetadata option : options)
               {
                  if (option.isNamed() && !valueMap.containsKey(option))
                  {
                     if (option.isRequired() || state.isDuplicateBuffer())
                        results.add("--" + option.getName() + " ");
                  }
               }
            }

         }

         // add to state
         if (!state.isFinalTokenComplete() && finalTokenIsValue)
         {
            state.setOption(context.getLastParsed());
            results.clear();
            if (state.isDuplicateBuffer())
            {
               // wait until the buffer remains the same until we append a space
               results.add(" ");
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

   {
      CommandParser commandParser = new CompositeCommandParser(new NamedBooleanOptionParser(),
               new NamedValueOptionParser(), new NamedValueVarargsOptionParser(), new OrderedValueOptionParser(),
               new OrderedValueVarargsOptionParser(), new NullTokenOptionParser());

      CommandParserContext context = new CommandParserContext();
      Map<OptionMetadata, Object> valueMap = commandParser.parse(command, tokens, context)
               .getValueMap();

      for (String warning : context.getWarnings())
      {
         ShellMessages.info(shell, warning);
      }

      Object[] parameters = new Object[command.getOptions().size()];
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

      OptionMetadata option = state.getOption();
      if ((option != null) && (state.getCommandContext() != null))
      {

         CommandParserContext commandContext = state.getCommandContext();
         Map<OptionMetadata, Object> valueMap = commandContext.getValueMap();
         if (valueMap.isEmpty() || valueMap.containsKey(option))
         {
            if (option.hasCustomCompleter())
            {
               CommandCompleter completer = BeanManagerUtils.getContextualInstance(manager, option.getCompleterType());
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

   private void getOptionCandidates(final CommandMetadata command, final PluginCommandCompleterState state)
   {
      ArrayList<String> results = new ArrayList<String>();
      Queue<String> tokens = state.getTokens();
      CommandParserContext context = new CommandParserContext();
      context.setCompleting(true);
      context.setFinalTokenComplete(state.isFinalTokenComplete());
      commandParser.parse(state.getCommand(), tokens,
               context);
      state.setCommandContext(context);
      Map<OptionMetadata, Object> valueMap = context.getValueMap();
      List<OptionMetadata> options = command.getOptions();

      if (tokens.isEmpty())
      {
         if (state.isFinalTokenComplete())
         {
            if ((context.isEmpty() || context.isLastOptionValued()))
            {
               for (OptionMetadata option : options)
               {
                  if (!valueMap.containsKey(option))
                  {
                     if (option.isNamed() && option.isRequired())
                     {
                        results.clear();
                        results.add("--" + option.getName() + " ");
                        break;
                     }
                     else if (option.isNamed())
                     {
                        results.add("--" + option.getName() + " ");
                     }
                     else if (!option.isNamed() && !option.isPipeOut() && !option.isPipeIn())
                     {
                        state.setOption(option);
                        break;
                     }
                  }
               }
            }
            else if (!context.isEmpty() && !context.isLastOptionValued())
            {
               state.setOption(context.getLastParsed());
            }
         }
         else
         {
            if (!state.isFinalTokenComplete() && !context.isEmpty())
            {
               state.setOption(context.getLastParsed());

               if (context.isLastOptionValued())
               {
                  state.getTokens().add(context.getLastParsedToken());
               }
            }
         }
      }
      else
      {
         String finalToken = tokens.peek();
         int finalTokenIndex = state.getBuffer().lastIndexOf(finalToken);

         boolean tailOptionValued = true;
         boolean finalTokenIsValue = false;
         if (!finalToken.startsWith("-"))
         {
            finalTokenIsValue = true;
            finalTokenIndex = state.getIndex();
         }
         else
         {
            boolean shortOption = finalToken.matches("^-[^\\-]+$")
                     && (finalToken.length() > 1);
            finalToken = finalToken.replaceFirst("^[-]+", "");
            for (Entry<OptionMetadata, Object> entry : valueMap.entrySet())
            {
               OptionMetadata option = entry.getKey();
               if (entry.getValue() == null)
               {
                  tailOptionValued = false;
               }
               if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
                        finalToken)))
               {
                  state.setOption(option);
               }
            }

            if (tailOptionValued)
            {
               for (OptionMetadata option : options)
               {
                  if (option.isNamed())
                  {
                     if (((option.getShortName().equals(finalToken) && shortOption) || option.getName().equals(
                              finalToken)) && valueMap.containsKey(option))
                     {
                        if (!state.isFinalTokenComplete())
                        {
                           results.add(" ");
                        }
                        break;
                     }
                     if (option.getName().startsWith(finalToken) && !valueMap.containsKey(option))
                     {
                        results.add("--" + option.getName() + " ");
                     }
                  }
               }
            }

            if (!results.isEmpty())
            {
               tokens.remove();
            }

            /*
             * If we haven't gotten any suggestions yet, then we just need to add everything we haven't seen yet. First
             * time - just the required options.
             */
            if (results.isEmpty() && tailOptionValued)
            {
               for (OptionMetadata option : options)
               {
                  if (option.isNamed() && !valueMap.containsKey(option))
                  {
                     if (option.isRequired() || state.isDuplicateBuffer())
                        results.add("--" + option.getName() + " ");
                  }
               }
            }

         }

         // add to state
         if (!state.isFinalTokenComplete() && finalTokenIsValue)
         {
            state.setOption(context.getLastParsed());
            results.clear();
            if (state.isDuplicateBuffer())
            {
               // wait until the buffer remains the same until we append a space
               results.add(" ");
View Full Code Here

Examples of org.jboss.forge.shell.command.parser.CommandParserContext

   {
      CommandParser commandParser = new CompositeCommandParser(new NamedBooleanOptionParser(),
               new NamedValueOptionParser(), new NamedValueVarargsOptionParser(), new OrderedValueOptionParser(),
               new OrderedValueVarargsOptionParser(), new NullTokenOptionParser());

      CommandParserContext context = new CommandParserContext();
      Map<OptionMetadata, Object> valueMap = commandParser.parse(command, tokens, context)
               .getValueMap();

      for (String warning : context.getWarnings())
      {
         ShellMessages.info(shell, warning);
      }

      Object[] parameters = new Object[command.getOptions().size()];
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.