Package org.jboss.forge.shell.command

Examples of org.jboss.forge.shell.command.OptionMetadata


         currentToken = currentToken.substring(2);
         if (command.hasOption(currentToken))
         {
            try
            {
               OptionMetadata option = command.getNamedOption(currentToken);
               if (option.isVarargs())
               {
                  tokens.remove();
                  List<String> args = new ArrayList<String>();
                  String rawValue = null;
                  // this has to be the last parameter... gobble the rest
View Full Code Here


         try
         {
            currentToken = currentToken.substring(2);
            if (command.hasOption(currentToken))
            {
               OptionMetadata option = command.getNamedOption(currentToken);
               tokens.remove();

               if (!option.isBoolean())
               {
                  String value = null;
                  if (!tokens.isEmpty())
                  {
                     String nextToken = tokens.peek();
View Full Code Here

         }

         int numberOrderedParams = ctx.getOrderedParamCount();
         try
         {
            OptionMetadata option = command.getOrderedOptionByIndex(numberOrderedParams);
            if (!option.isVarargs())
            {
               ctx.put(option, Strings.stripQuotes(currentToken), Strings.stripQuotes(tokens.remove()));
               ctx.incrementParmCount();
            }
         }
View Full Code Here

         if (((candidates.size() == 1) && "".equals(candidates.get(0)))
                  || (state.isDuplicateBuffer() && state.isFinalTokenComplete()))
         {
            if (commandHolder.getState().getOption() != null)
            {
               OptionMetadata option = commandHolder.getState().getOption();
               reader.println();
               reader.println(option.getOptionDescriptor());
               if (candidates.size() == 1)
               {
                  reader.println();
                  reader.drawLine();
                  return true;
View Full Code Here

   private static void processOption(final CommandParserContext ctx, final Queue<String> tokens,
                                     final CommandMetadata command, final String currentToken,
                                     final boolean shortOption)
   {
      OptionMetadata option = command.getNamedOption(currentToken);

      if (option.isBoolean())
      {
         String value = "true";
         if (!tokens.isEmpty())
         {
            if (!shortOption)
            {
               tokens.remove();
            }
            String nextToken = tokens.peek();
            if (!option.isFlagOnly() && (nextToken != null) && nextToken.matches("true|false"))
            {
               value = nextToken;
               tokens.remove();
            }
         }
View Full Code Here

            if (((candidates.size() == 1) && "".equals(candidates.get(0)))
                        || (state.isDuplicateBuffer() && state.isFinalTokenComplete()))
            {
                if (commandHolder.getState().getOption() != null)
                {
                    OptionMetadata option = commandHolder.getState().getOption();
                    reader.println();
                    reader.println(option.getOptionDescriptor());
                    if (candidates.size() == 1)
                    {
                        reader.println();
                        reader.drawLine();
                        return true;
View Full Code Here

   @Override
   public void complete(final CommandCompleterState st)
   {
      PluginCommandCompleterState state = ((PluginCommandCompleterState) st);

      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());
               if (completer == null)
               {
                  throw new RuntimeException("Could not instantiate completer of type: "
                           + option.getCompleterType().getName()
                           + ", completers must be valid CDI beans (public top-level classes.)");
               }
               completer.complete(state);
            }
            else if (option.isEnum())
            {
               @SuppressWarnings("unchecked")
               EnumCompleter completer = new EnumCompleter((Class<Enum<?>>) option.getType());
               completer.complete(state);
            }
            else if (isJavaResourceAssignable(option))
            {
               completeJavaPaths(state, option, valueMap, new ResourceFilter()
View Full Code Here

         if (((candidates.size() == 1) && "".equals(candidates.get(0)))
                  || (state.isDuplicateBuffer() && state.isFinalTokenComplete()))
         {
            if (commandHolder.getState().getOption() != null)
            {
               OptionMetadata option = commandHolder.getState().getOption();
               reader.println();
               reader.println(option.getOptionDescriptor());
               if (candidates.size() == 1)
               {
                  reader.println();
                  reader.drawLine();
                  return true;
View Full Code Here

         try
         {
            currentToken = currentToken.substring(2);
            if (command.hasOption(currentToken))
            {
               OptionMetadata option = command.getNamedOption(currentToken);
               tokens.remove();

               if (!option.isBoolean())
               {
                  String value = null;
                  if (!tokens.isEmpty())
                  {
                     String nextToken = tokens.peek();
View Full Code Here

            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() + " ");
                  }
               }
            }

         }
View Full Code Here

TOP

Related Classes of org.jboss.forge.shell.command.OptionMetadata

Copyright © 2018 www.massapicom. 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.