Package org.jboss.aesh.cl

Examples of org.jboss.aesh.cl.ParsedCompleteObject


         try
         {
            // We are dealing with one-level commands only.
            // Eg. new-project-type --named ... instead of new-project-type setup --named ...
            // cmd.populateInputs(line, true);
            ParsedCompleteObject completeObject = cmd.parseCompleteObject(line);
            if (completeObject.doDisplayOptions())
            {
               List<String> options = cmd.getCompletionOptions(completeObject.getName(), line);
               completeOperation.addCompletionCandidates(options);
               if (completeOperation.getCompletionCandidates().size() == 1)
               {
                  completeOperation.setOffset(completeOperation.getCursor() - completeObject.getOffset());
               }
            }
            else
            {
               final InputComponent<?, Object> input;
               if (completeObject.isOption())
               {
                  // try to complete an option value. Eg: "--xxx"
                  input = cmd.getInputs().get(completeObject.getName());
               }
               // try to complete a argument value Eg: ls . (. is the argument)
               else if (completeObject.isArgument())
               {
                  input = cmd.getInputs().get(ARGUMENTS_INPUT_NAME); // default for arguments
               }
               else
               {
                  input = null;
               }
               if (input != null)
               {
                  CompletionStrategy completionObj = CompletionStrategyFactory.getCompletionFor(input);
                  completionObj.complete(completeOperation, input, shellContext, completeObject.getValue(),
                           shell.getConverterFactory());
               }
            }
         }
         catch (ArgumentParserException e)
View Full Code Here


               defaultCompletion(completeOperation);
           }
           // complete options/arguments
           else if (completeOperation.getBuffer().startsWith(param.getName()))
           {
               ParsedCompleteObject completeObject = null;
               completeObject = new CommandLineCompletionParser(context.getParser())
                       .findCompleteObject(completeOperation.getBuffer());
               //logger.info("ParsedCompleteObject: " + completeObject);
               if (completeObject.doDisplayOptions())
               {
                   // we have a partial/full name
                   if (completeObject.getName() != null && completeObject.getName().length() > 0)
                   {
                       if (param.findPossibleLongNamesWitdDash(completeObject.getName()).size() > 0)
                       {
                           // only one param
                           if (param.findPossibleLongNamesWitdDash(completeObject.getName()).size() == 1)
                           {
                               completeOperation.addCompletionCandidate(param.findPossibleLongNamesWitdDash(
                                       completeObject.getName()).get(0));
                               completeOperation.setOffset(completeOperation.getCursor() -
                                       completeObject.getOffset());
                           }
                           // multiple params
                           else
                               completeOperation.addCompletionCandidates(param.findPossibleLongNamesWitdDash(completeObject
                                       .getName()));
                       }
                   }
                   // display all our params
                   else
                   {
                       if (param.getOptionLongNamesWithDash().size() > 1)
                       {
                           completeOperation.addCompletionCandidates(param.getOptionLongNamesWithDash());
                       }
                       else
                       {
                           completeOperation.addCompletionCandidates(param.getOptionLongNamesWithDash());
                           completeOperation.setOffset(completeOperation.getCursor() -
                                   completeObject.getOffset());
                       }
                   }
               }
               // try to complete an options value
               else if (completeObject.isOption())
               {
                   optionCompletion(completeOperation, completeObject);
               }
               // try to complete a argument value
               else if (completeObject.isArgument())
               {
                   argumentCompletion(completeOperation, completeObject);
               }
           }
       }
View Full Code Here

         completeOperation.addCompletionCandidates(param.getOptionLongNamesWithDash());
      }
      // complete options/arguments
      else if (completeOperation.getBuffer().startsWith(param.getName()))
      {
         ParsedCompleteObject completeObject = null;
         try
         {
            completeObject = new CommandLineCompletionParser(context.getParser())
                     .findCompleteObject(completeOperation.getBuffer());
         }
         catch (CommandLineParserException e)
         {
            logger.info(e.getMessage());
            return;
         }
         logger.info("ParsedCompleteObject: " + completeObject);
         if (completeObject.doDisplayOptions())
         {
            // we have a partial/full name
            if (completeObject.getName() != null && completeObject.getName().length() > 0)
            {
               if (param.findPossibleLongNamesWitdDash(completeObject.getName()).size() > 0)
               {
                  // only one param
                  if (param.findPossibleLongNamesWitdDash(completeObject.getName()).size() == 1)
                  {
                     completeOperation.addCompletionCandidate(param.findPossibleLongNamesWitdDash(
                              completeObject.getName()).get(0));
                     completeOperation.setOffset(completeOperation.getCursor() -
                              completeObject.getOffset());
                  }
                  // multiple params
                  else
                     completeOperation.addCompletionCandidates(param.findPossibleLongNamesWitdDash(completeObject
                              .getName()));
               }
            }
            // display all our params
            else
            {
               if (param.getOptionLongNamesWithDash().size() > 1)
               {
                  completeOperation.addCompletionCandidates(param.getOptionLongNamesWithDash());
               }
               else
               {
                  completeOperation.addCompletionCandidates(param.getOptionLongNamesWithDash());
                  completeOperation.setOffset(completeOperation.getCursor() -
                           completeObject.getOffset());
               }
            }
         }
         // try to complete an options value
         else if (completeObject.isOption())
         {
            InputComponent inputOption = context.findInput(completeObject.getName());
            // option type == File
            if (inputOption != null && inputOption.getValueType() == File.class)
            {
               completeOperation.setOffset(completeOperation.getCursor());
               if (completeObject.getValue() == null)
                  new FileLister("", new File(System.getProperty("user.dir")))
                           .findMatchingDirectories(completeOperation);
               else
                  new FileLister(completeObject.getValue(), new File(System.getProperty("user.dir")))
                           .findMatchingDirectories(completeOperation);
            }
            else if (inputOption != null && inputOption.getValueType() == Boolean.class)
            {
               // TODO
            }
            else if (inputOption != null && inputOption.getValueType() == String.class)
            {
               // if it has a default value we can try to auto complete that
               if (inputOption instanceof UIInput)
               {
                  if (completeObject.getValue() == null || ((((UIInput) inputOption).getValue() != null) &&
                           completeObject.getValue().startsWith(((UIInput) inputOption).getValue().toString())))
                  {
                     completeOperation.addCompletionCandidate(((UIInput) inputOption).getValue().toString());
                  }
               }
            }
            // this shouldnt be needed
            if (inputOption != null && inputOption instanceof UIInput)
            {
               Iterable<String> iter = ((UIInput) inputOption).getCompleter().getCompletionProposals(inputOption,
                        completeObject.getValue());
               if (iter != null)
               {
                  for (String s : iter)
                     completeOperation.addCompletionCandidate(s);
               }
               if (completeOperation.getCompletionCandidates().size() == 1)
               {
                  completeOperation.setOffset(completeOperation.getCursor() -
                           completeObject.getOffset());
               }
            }
         }
         // try to complete a argument value
         else if (completeObject.isArgument())
         {
            InputComponent inputOption = context.findInput("arguments"); // default for arguments

            if (inputOption != null && inputOption.getValueType() == File.class)
            {
               completeOperation.setOffset(completeOperation.getCursor());
               if (completeObject.getValue() == null)
                  new FileLister("", new File(System.getProperty("user.dir")))
                           .findMatchingDirectories(completeOperation);
               else
                  new FileLister(completeObject.getValue(), new File(System.getProperty("user.dir")))
                           .findMatchingDirectories(completeOperation);
            }
            else if (inputOption != null && inputOption.getValueType() == Boolean.class)
            {
               // TODO
            }
            // check if the command actually implements Completion
            else if (command instanceof Completion)
            {
               ((Completion) command).complete(completeOperation);
            }
            else
            {
               // this shouldnt be needed
               if (inputOption != null && inputOption instanceof UIInputMany)
               {
                  Iterable<String> iter = ((UIInputMany) inputOption).getCompleter().getCompletionProposals(
                           inputOption, completeObject.getValue());
                  if (iter != null)
                  {
                     for (String s : iter)
                     {
                        completeOperation.addCompletionCandidate(s);
                     }
                  }
                  if (completeOperation.getCompletionCandidates().size() == 1)
                  {
                     completeOperation.setOffset(completeOperation.getCursor() -
                              completeObject.getOffset());
                  }
               }
            }
         }
      }
View Full Code Here

TOP

Related Classes of org.jboss.aesh.cl.ParsedCompleteObject

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.