Package org.apache.oodt.cas.cli.option

Examples of org.apache.oodt.cas.cli.option.CmdLineOptionInstance


   }

   @VisibleForTesting
   /* package */static CmdLineOptionInstance getOption(CmdLineIterable<ParsedArg> args,
         CmdLineOption option) throws CmdLineConstructionException {
      CmdLineOptionInstance specifiedOption = new CmdLineOptionInstance();
      specifiedOption.setOption(option);
      List<String> values = getValues(args);
      if (isHelpOption(option)) {
         specifiedOption.setValues(values);        
      } else if (option.hasArgs()) {
         if (!values.isEmpty()) {
            specifiedOption.setValues(values);
         } else if (!option.hasStaticArgs()) {
            throw new CmdLineConstructionException("Option " + option + " requires args");
         }
      } else if (!option.hasArgs() && !values.isEmpty()) {
         throw new CmdLineConstructionException("Option " + option + " does not support args");
View Full Code Here


    */
   public static CmdLineOptionInstance findSpecifiedPrintSupportedActionsOption(
         Set<CmdLineOptionInstance> options) {
      Validate.notNull(options);

      CmdLineOptionInstance specifiedPsa = null;
      for (CmdLineOptionInstance option : options) {
         if (isPrintSupportedActionsOption(option.getOption())) {
            if (specifiedPsa != null) {
               throw new IllegalArgumentException(
                     "Only on print supported actions option can be specified!");
View Full Code Here

    */
   public static CmdLineOptionInstance findSpecifiedActionOption(
         Set<CmdLineOptionInstance> options) {
      Validate.notNull(options);

      CmdLineOptionInstance specifiedAction = null;
      for (CmdLineOptionInstance option : options) {
         if (option.isAction()) {
            if (specifiedAction != null) {
               throw new IllegalArgumentException(
                     "Only one action may be specified!");
            }
            specifiedAction = option;
         } else if (option.isGroup()) {
            CmdLineOptionInstance foundAction = findSpecifiedActionOption(option
                  .getSubOptions());
            if (specifiedAction != null && foundAction != null) {
               throw new IllegalArgumentException(
                  "Only one action may be specified!");
            } else if (foundAction != null) {
View Full Code Here

    */
   public static CmdLineOptionInstance findSpecifiedHelpOption(
         Set<CmdLineOptionInstance> options) {
      Validate.notNull(options);

      CmdLineOptionInstance specifiedHelp = null;
      for (CmdLineOptionInstance option : options) {
         if (isHelpOption(option.getOption())) {
            if (specifiedHelp != null) {
               throw new IllegalArgumentException(
                     "Help can only be specified once!");
View Full Code Here

   private final static Set<CmdLineOption> SUPPORTED_OPTIONS = newHashSet(
         (CmdLineOption) ACTION_OPTION, (CmdLineOption) HELP_OPTION,
         (CmdLineOption) PSA_ACTION);

   public void testBaseCase() {
      CmdLineOptionInstance specifiedAction = createOptionInstance(
            ACTION_OPTION, TEST_ACTION_1.getName());
      Set<CmdLineOptionInstance> specifiedOptions = newHashSet(specifiedAction);
      CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, SUPPORTED_OPTIONS,
            specifiedOptions);
      assertEquals(TEST_ACTION_1, args.getSpecifiedAction());
View Full Code Here

      assertNull(args.getHelpOptionInst());
      assertNull(args.getPrintSupportedActionsOptionInst());
   }

   public void testCaseActionNotSupported() {
      CmdLineOptionInstance specifiedAction = createOptionInstance(
            ACTION_OPTION, "NotSupportedActionName");
      Set<CmdLineOptionInstance> specifiedOptions = newHashSet(specifiedAction);
      CmdLineArgs args = new CmdLineArgs(SUPPORTED_ACTIONS, SUPPORTED_OPTIONS,
            specifiedOptions);

      // Verify that CmdLineAction is null since it was not able to be located
      // in set of supported actions.
      assertNull(args.getSpecifiedAction());
      // Verify that if did find the action option.
      assertEquals(specifiedAction.getOption(), args.getActionOptionInst()
            .getOption());
      // Verify that if found the specified action even though it is not
      // supported.
      assertEquals(newArrayList("NotSupportedActionName"), args
            .getActionOptionInst().getValues());
View Full Code Here

      option.setShortOption("t");
      option.setLongOption("test");
      option.setHasArgs(true);

      // Test 1 value specified.
      CmdLineOptionInstance instance = new CmdLineOptionInstance(
            option, Lists.newArrayList("value"));
      CrawlerBeansPropHandler handler = new CrawlerBeansPropHandler();
      handler.initialize(option);
      handler.setProperties(Lists.newArrayList("TestBean.prop"));
      handler.handleOption(null, instance);
      assertEquals(1, getProperties().size());
      assertEquals("value", getProperties().getProperty("TestBean.prop"));
      getProperties().clear();

      // Test multiple values specified.
      instance = new CmdLineOptionInstance(
            option, Lists.newArrayList("value1", "value2"));
      handler = new CrawlerBeansPropHandler();
      handler.initialize(option);
      handler.setProperties(Lists.newArrayList("TestBean.prop"));
      handler.handleOption(null, instance);
      assertEquals(2, getProperties().size());
      assertEquals("value1", getProperties().getProperty("TestBean.prop[0]"));
      assertEquals("value2", getProperties().getProperty("TestBean.prop[1]"));
      getProperties().clear();

      // Test no values specified.
      try {
         instance = new CmdLineOptionInstance(
               option, Collections.<String>emptyList());
         handler = new CrawlerBeansPropHandler();
         handler.initialize(option);
         handler.setProperties(Lists.newArrayList("TestBean.prop"));
         handler.handleOption(null, instance);
View Full Code Here

            CmdLineUtils.getOptionByName(actionOption.getLongOption(), options));
   }

   public void testGetOptionInstanceByName() {
      CmdLineAction action = createAction("action");
      CmdLineOptionInstance userOptionInst, urlOptionInst, passOptionInst, actionOptionInst;
      HashSet<CmdLineOptionInstance> optionInsts = Sets.newHashSet(
            userOptionInst = new CmdLineOptionInstance(createSimpleOption(
                  "user", "username", false), new ArrayList<String>()),
            urlOptionInst = new CmdLineOptionInstance(createSimpleOption("u",
                  "url", createRequiredRequirementRule(action)),
                  new ArrayList<String>()),
            passOptionInst = new CmdLineOptionInstance(createSimpleOption(
                  "pass", "password", false), new ArrayList<String>()),
            actionOptionInst = new CmdLineOptionInstance(
                  createActionOption("action"), new ArrayList<String>()));

      assertEquals(userOptionInst, CmdLineUtils.getOptionInstanceByName(
            userOptionInst.getOption().getShortOption(), optionInsts));
      assertEquals(userOptionInst, CmdLineUtils.getOptionInstanceByName(
            userOptionInst.getOption().getLongOption(), optionInsts));
      assertEquals(urlOptionInst, CmdLineUtils.getOptionInstanceByName(
            urlOptionInst.getOption().getShortOption(), optionInsts));
      assertEquals(urlOptionInst, CmdLineUtils.getOptionInstanceByName(
            urlOptionInst.getOption().getLongOption(), optionInsts));
      assertEquals(passOptionInst, CmdLineUtils.getOptionInstanceByName(
View Full Code Here

            null);
      performAndQuitOption.setPerformAndQuit(true);
      AdvancedCmdLineOption otherOption = createAdvancedOption("help", null);
      otherOption.setPerformAndQuit(false);

      CmdLineOptionInstance performAndQuitOptionInstance = new CmdLineOptionInstance(
            performAndQuitOption, new ArrayList<String>());
      CmdLineOptionInstance otherInstance = new CmdLineOptionInstance(
            otherOption, new ArrayList<String>());

      assertEquals(Sets.newHashSet(performAndQuitOptionInstance),
            CmdLineUtils.findPerformAndQuitOptions(Sets.newHashSet(
                  performAndQuitOptionInstance, otherInstance)));
View Full Code Here

            createOptionInstance(createSimpleOption("test1", false)),
            createOptionInstance(createSimpleOption("test2", false)));

      assertTrue(CmdLineUtils.findAllOfSpecifiedOption(findOption, options)
            .isEmpty());
      CmdLineOptionInstance firstOption = createOptionInstance(findOption,
            "first");
      CmdLineOptionInstance secondOption = createOptionInstance(findOption,
            "second");
      options.add(firstOption);
      assertEquals(Sets.newHashSet(firstOption),
            CmdLineUtils.findAllOfSpecifiedOption(findOption, options));
      options.add(secondOption);
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.cli.option.CmdLineOptionInstance

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.