Java Code Examples for com.beust.jcommander.JCommander#setAcceptUnknownOptions()

The following examples show how to use com.beust.jcommander.JCommander#setAcceptUnknownOptions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjCGenerator.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   Arguments arguments = new Arguments();
   JCommander jc = new JCommander(arguments);
   jc.setAcceptUnknownOptions(true);
   jc.parse(args);

   List<String> paths = Arrays.asList(arguments.input + "/capability", arguments.input + "/service");

   try {
      for(String path : paths) {
         List<Definition> definitions = readDefinitions(path);
         generateSource(arguments.template, arguments.output, definitions);
      }
   } catch(Exception e) {
      logger.error("Failed to read or generate source!", e);
      throw e;
   }
}
 
Example 2
Source File: SwiftGenerator.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   Arguments arguments = new Arguments();
   JCommander jc = new JCommander(arguments);
   jc.setAcceptUnknownOptions(true);
   jc.parse(args);

   List<String> paths = Arrays.asList(arguments.input + "/capability", arguments.input + "/service");

   try {
      for(String path : paths) {
         List<Definition> definitions = readDefinitions(path);
         generateSource(arguments.template, arguments.output, definitions);
      }
   } catch(Exception e) {
      logger.error("Failed to read or generate source!", e);
      throw e;
   }
}
 
Example 3
Source File: AosGenerator.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
   Arguments arguments = new Arguments();
   JCommander jc = new JCommander(arguments);
   jc.setAcceptUnknownOptions(true);
   jc.parse(args);
   
   String path = System.getProperty("user.dir");
   
   File input = arguments.input.startsWith("/") ? new File(arguments.input) : new File(path, arguments.input);
   File output = arguments.output.startsWith("/") ? new File(arguments.output) : new File(path, arguments.output);
   
   AdapterReader bindingReader = new AdapterReader();
   AdapterContext context = bindingReader.readBindings(input);
         
   try {
      JavaProcessor processor = new JavaProcessor(arguments.template, output.getAbsolutePath());
      processor.createClasses(context);
   } catch (IOException e) {
      logger.error("Could not create ipcd aos adapter classes!");
      e.printStackTrace();
      System.exit(-1);
   }
}
 
Example 4
Source File: ModelGenerator.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
   Arguments arguments = new Arguments();
   JCommander jc = new JCommander(arguments);
   jc.setAcceptUnknownOptions(true);
   jc.parse(args);

   String path = System.getProperty("user.dir");
   
   File input = arguments.input.startsWith("/") ? new File(arguments.input) : new File(path, arguments.input);
   File output = arguments.output.startsWith("/") ? new File(arguments.output) : new File(path, arguments.output);
   
   DefinitionReader bindingReader = new DefinitionReader();
   DefinitionContext context = bindingReader.readBindings(input);
         
   try {
      JavaProcessor processor = new JavaProcessor(arguments.template, output.getAbsolutePath());
      processor.createClasses(context);
   } catch (IOException e) {
      logger.error("Could not create ipcd bindings!");
      e.printStackTrace();
      System.exit(-1);
   }
}
 
Example 5
Source File: LcovMergerFlags.java    From bazel with Apache License 2.0 6 votes vote down vote up
static LcovMergerFlags parseFlags(String[] args) {
  LcovMergerFlags flags = new LcovMergerFlags();
  JCommander jCommander = new JCommander(flags);
  jCommander.setAllowParameterOverwriting(true);
  jCommander.setAcceptUnknownOptions(true);
  try {
    jCommander.parse(args);
  } catch (ParameterException e) {
    throw new IllegalArgumentException("Error parsing args", e);
  }
  if (flags.coverageDir == null && flags.reportsFile == null) {
    throw new IllegalArgumentException(
        "At least one of coverage_dir or reports_file should be specified.");
  }
  if (flags.coverageDir != null && flags.reportsFile != null) {
    logger.warning("Overriding --coverage_dir value in favor of --reports_file");
  }
  if (flags.outputFile == null) {
    throw new IllegalArgumentException("output_file was not specified.");
  }
  return flags;
}
 
Example 6
Source File: IrisAbstractApplication.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static void exec(Class<? extends IrisAbstractApplication> appClazz, Collection<Class<? extends Module>> modules, String... args) {
   Arguments arguments = new Arguments();
   JCommander jc = new JCommander(arguments);
   jc.setAcceptUnknownOptions(true);
   try {
      jc.parse(args);
   }
   catch(RuntimeException e) {
      System.out.println("Error parsing arguments: " + e.getMessage());
      jc.usage();
      System.exit(-1);
   }

   exec(appClazz, modules, arguments);
}
 
Example 7
Source File: Cli.java    From apiman-cli with Apache License 2.0 5 votes vote down vote up
@Override
public void run(List<String> args, JCommander jc) {
    jc.setAcceptUnknownOptions(false);
    jc.setProgramName("apiman-cli");
    jc.addObject(this);
    build(jc);
    try {
        jc.parse(args.toArray(new String[]{}));
        super.run(args, jc);
    } catch (ParameterException | CommandException e) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(e.getMessage(), e);
        } else {
            if (e.getCause() == null) {
                LOGGER.error(e.getMessage());
            } else {
                LOGGER.error("{}: {}", e.getMessage(), e.getCause().getMessage());
            }
        }
        printUsage(jc, false);
    } catch (ExitWithCodeException ec) {
        // print the message and exit with the given code
        LogUtil.OUTPUT.error(ec.getMessage());
        if (ec.isPrintUsage()) {
            printUsage(jc, ec.getExitCode());
        } else {
            System.exit(ec.getExitCode());
        }
    }
}
 
Example 8
Source File: L10nJCommander.java    From mojito with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link JCommander} instance for a single run (sub-sequent
 * parsing are not supported but required for testing).
 */
public void createJCommanderForRun() {
    logger.debug("Create JCommander instance");
    jCommander = new JCommander();

    jCommander.setAcceptUnknownOptions(true);

    logger.debug("Initialize the JCommander instance");
    jCommander.setProgramName(PROGRAM_NAME);

    logger.debug("Set the main command for version/help directly on the JCommander");
    jCommander.addObject(mainCommand);

    logger.debug("Register Commands retreived using Spring");
    for (Command command : applicationContext.getBeansOfType(Command.class).values()) {

        Map<String, JCommander> jCommands = jCommander.getCommands();

        for (String name : command.getNames()) {
            if (jCommands.keySet().contains(name)) {
                throw new RuntimeException("There must be only one module with name: " + name);
            }
        }

        commands.put(command.getName(), command);
        jCommander.addCommand(command);
    }
}
 
Example 9
Source File: AndroidDeviceTestSuite.java    From android-test with Apache License 2.0 5 votes vote down vote up
Builder withCommandLineArgs(String[] args) {
  JCommander jCommander = new JCommander(testArgs);
  jCommander.setAcceptUnknownOptions(true);
  jCommander.parse(args);
  this.allowEmptySuite = testArgs.havingNoTestsToRunIsFineWithMe;
  this.commandLineArgs = args;
  return this;
}
 
Example 10
Source File: AndroidGoogleTest.java    From android-test with Apache License 2.0 5 votes vote down vote up
Builder withCommandLineArgs(String[] args) {
  JCommander jCommander = new JCommander(testArgs);
  jCommander.setAcceptUnknownOptions(true);
  jCommander.parse(args);
  this.buffers = testArgs.testLogcatBuffer;
  this.testFilters = testArgs.testLogcatFilters;
  this.outputFormat = testArgs.testLogcatFormat;
  this.testDebug = testArgs.enableDebug;
  this.gatherOutputs = testArgs.gatherTestOutputs;
  return this;
}
 
Example 11
Source File: FlagParsingFilter.java    From android-test with Apache License 2.0 5 votes vote down vote up
public final void parse(String[] testArgs) {
  JCommander jCommander = new JCommander(this);
  jCommander.setAcceptUnknownOptions(true);
  jCommander.setAllowParameterOverwriting(true);
  jCommander.parse(testArgs);
  flagsParsed = true;
}
 
Example 12
Source File: DeviceBrokerOptions.java    From android-test with Apache License 2.0 5 votes vote down vote up
Builder withCommandlineArgs(String[] testArgs) {
  JCommander jCommander = new JCommander(this);
  jCommander.setAcceptUnknownOptions(true);
  jCommander.setAllowParameterOverwriting(true);
  jCommander.parse(testArgs);
  return this;
}
 
Example 13
Source File: CommandLine.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
/**
 * Applies arg values to the options object.
 *
 * @param args Command line arguments.
 */
@VisibleForTesting
public static CliOptions parseOptions(String... args) {
  JCommander parser = null;
  try {
    parser = prepareParser(new CliOptions(ImmutableList.copyOf(customOptions)));

    // We first perform a 'dummy' parsing round.  This induces classloading on any third-party
    // code, where they can statically invoke registerCustomOptions().
    parser.setAcceptUnknownOptions(true);
    parser.parseWithoutValidation(args);

    CliOptions options = new CliOptions(ImmutableList.copyOf(customOptions));
    parser = prepareParser(options);
    parser.parse(args);

    LOG.info("-----------------------------------------------------------------------");
    LOG.info("Parameters:");
    parser.getParameters().stream()
        .map(param ->
            param.getLongestName() + ": " + param.getParameterized().get(param.getObject()))
        .sorted()
        .forEach(LOG::info);
    LOG.info("-----------------------------------------------------------------------");

    instance = options;
    return options;
  } catch (ParameterException e) {
    if (parser != null) {
      parser.usage();
    }
    LOG.error(e.getMessage());
    System.exit(1);
    throw new RuntimeException(e);
  }
}
 
Example 14
Source File: CommandInput.java    From Scribengin with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> map(Object object, List<String> argsList) {
  this.object = object ;
  mainParameters = new ArrayList<String>();
  String[] args = argsList.toArray(new String[argsList.size()]) ;
  JCommander jcommander = new JCommander(this) ;
  jcommander.setAcceptUnknownOptions(true);
  jcommander.parse(args);
  List<String> remainOptions = new ArrayList<String>() ;
  remainOptions.addAll(jcommander.getUnknownOptions()) ;
  remainOptions.addAll(mainParameters) ;
  return remainOptions ;
}
 
Example 15
Source File: WalkModDispatcher.java    From walkmod-core with GNU Lesser General Public License v3.0 3 votes vote down vote up
public static void main(String[] args) throws Exception {

		WalkModDispatcher instance = new WalkModDispatcher();
		JCommander command = new JCommander(instance);

		command.setProgramName("walkmod");
		command.setAcceptUnknownOptions(false);

		instance.execute(command, args);

	}
 
Example 16
Source File: WalkModDispatcher.java    From walkmod-core with GNU Lesser General Public License v3.0 3 votes vote down vote up
public static void main(String[] args) throws Exception {

		WalkModDispatcher instance = new WalkModDispatcher();
		JCommander command = new JCommander(instance);

		command.setProgramName("walkmod");
		command.setAcceptUnknownOptions(false);

		instance.execute(command, args);

	}