Search in sources :

Example 16 with JCommander

use of com.beust.jcommander.JCommander in project midpoint by Evolveum.

the class Main method start.

private void start(String[] args) {
    LOG.debug("Arguments: {}", Arrays.toString(args));
    DefaultCommand def = new DefaultCommand();
    JCommander commander = new JCommander(def);
    for (Map.Entry<String, ActionValue> entry : ACTIONS.entrySet()) {
        ActionValue value = entry.getValue();
        commander.addCommand(entry.getKey(), value.command);
    }
    commander.parse(args);
    String cmd = commander.getParsedCommand();
    LOG.debug("Parsed command: '{}'", cmd);
    if (StringUtils.isEmpty(cmd)) {
        if (def.isVersion()) {
            printVersion();
        }
        if (def.isHelp()) {
            printHelp(commander);
        }
        return;
    }
    ActionValue actionValue = null;
    for (Map.Entry<String, ActionValue> entry : ACTIONS.entrySet()) {
        if (cmd != null && cmd.equals(entry.getKey())) {
            actionValue = entry.getValue();
            break;
        }
    }
    if (actionValue == null) {
        printHelp(commander);
        return;
    }
    try {
        LOG.debug("Executing action {} with params {}", actionValue.action.getSimpleName(), actionValue.command);
        Action action = createAction(actionValue.action, actionValue.command, commander);
        action.execute();
    } catch (Exception ex) {
        handleError(ex);
    }
}
Also used : JCommander(com.beust.jcommander.JCommander) DefaultCommand(com.evolveum.midpoint.cli.common.DefaultCommand) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 17 with JCommander

use of com.beust.jcommander.JCommander in project intellij-community by JetBrains.

the class RemoteTestNGStarter method main.

public static void main(String[] args) throws Exception {
    int i = 0;
    String param = null;
    String commandFileName = null;
    String workingDirs = null;
    Vector resultArgs = new Vector();
    for (; i < args.length; i++) {
        String arg = args[i];
        if (arg.startsWith("@name")) {
            param = arg.substring(5);
            continue;
        } else if (arg.startsWith("@w@")) {
            workingDirs = arg.substring(3);
            continue;
        } else if (arg.startsWith("@@@")) {
            commandFileName = arg.substring(3);
            continue;
        } else if (arg.startsWith(ForkedDebuggerHelper.DEBUG_SOCKET)) {
            continue;
        } else if (arg.startsWith(SOCKET)) {
            final int port = Integer.parseInt(arg.substring(SOCKET.length()));
            try {
                //start collecting tests
                final Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), port);
                final DataInputStream os = new DataInputStream(socket.getInputStream());
                try {
                    //wait for ready flag
                    os.readBoolean();
                } finally {
                    os.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            //do not add socket to actual params
            continue;
        } else if (arg.equals("-temp")) {
            break;
        }
        resultArgs.add(arg);
    }
    final File temp = new File(args[++i]);
    final BufferedReader reader = new BufferedReader(new FileReader(temp));
    final List newArgs = new ArrayList();
    try {
        final String cantRunMessage = "CantRunException";
        while (true) {
            String line = reader.readLine();
            while (line == null) {
                line = reader.readLine();
            }
            if (line.startsWith(cantRunMessage) && !new File(line).exists()) {
                System.err.println(line.substring(cantRunMessage.length()));
                while (true) {
                    line = reader.readLine();
                    if (line == null || line.equals("end"))
                        break;
                    System.err.println(line);
                }
                System.exit(1);
                return;
            }
            if (line.equals("end"))
                break;
            newArgs.add(line);
        }
    } finally {
        reader.close();
    }
    resultArgs.addAll(newArgs);
    if (commandFileName != null) {
        if (workingDirs != null && new File(workingDirs).length() > 0) {
            System.exit(new TestNGForkedSplitter(workingDirs, newArgs).startSplitting(args, param, commandFileName, null));
            return;
        }
    }
    final IDEARemoteTestNG testNG = new IDEARemoteTestNG(param);
    CommandLineArgs cla = new CommandLineArgs();
    new JCommander(Collections.singletonList(cla), (String[]) resultArgs.toArray(new String[resultArgs.size()]));
    testNG.configure(cla);
    testNG.run();
}
Also used : ArrayList(java.util.ArrayList) JCommander(com.beust.jcommander.JCommander) List(java.util.List) ArrayList(java.util.ArrayList) Vector(java.util.Vector) Socket(java.net.Socket)

Example 18 with JCommander

use of com.beust.jcommander.JCommander in project zxing by zxing.

the class CommandLineEncoder method main.

public static void main(String[] args) throws Exception {
    EncoderConfig config = new EncoderConfig();
    JCommander jCommander = new JCommander(config, args);
    jCommander.setProgramName(CommandLineEncoder.class.getSimpleName());
    if (config.help) {
        jCommander.usage();
        return;
    }
    String outFileString = config.outputFileBase;
    if (EncoderConfig.DEFAULT_OUTPUT_FILE_BASE.equals(outFileString)) {
        outFileString += '.' + config.imageFormat.toLowerCase(Locale.ENGLISH);
    }
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    if (config.errorCorrectionLevel != null) {
        hints.put(EncodeHintType.ERROR_CORRECTION, config.errorCorrectionLevel);
    }
    BitMatrix matrix = new MultiFormatWriter().encode(config.contents.get(0), config.barcodeFormat, config.width, config.height, hints);
    MatrixToImageWriter.writeToPath(matrix, config.imageFormat, Paths.get(outFileString));
}
Also used : EncodeHintType(com.google.zxing.EncodeHintType) MultiFormatWriter(com.google.zxing.MultiFormatWriter) JCommander(com.beust.jcommander.JCommander) BitMatrix(com.google.zxing.common.BitMatrix) EnumMap(java.util.EnumMap)

Example 19 with JCommander

use of com.beust.jcommander.JCommander in project smali by JesusFreke.

the class ListCommand method setupCommand.

@Override
protected void setupCommand(JCommander jc) {
    List<JCommander> hierarchy = getCommandHierarchy();
    ExtendedCommands.addExtendedCommand(jc, new ListStringsCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListMethodsCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListFieldsCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListTypesCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListClassesCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListDexCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListVtablesCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListFieldOffsetsCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListDependenciesCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListHelpCommand(hierarchy));
    ExtendedCommands.addExtendedCommand(jc, new ListHlepCommand(hierarchy));
}
Also used : JCommander(com.beust.jcommander.JCommander) ListHlepCommand(org.jf.baksmali.ListHelpCommand.ListHlepCommand)

Example 20 with JCommander

use of com.beust.jcommander.JCommander in project smali by JesusFreke.

the class ListCommand method run.

@Override
public void run() {
    JCommander jc = getJCommander();
    if (help || jc.getParsedCommand() == null) {
        usage();
        return;
    }
    Command command = (Command) jc.getCommands().get(jc.getParsedCommand()).getObjects().get(0);
    command.run();
}
Also used : ListHlepCommand(org.jf.baksmali.ListHelpCommand.ListHlepCommand) Command(org.jf.util.jcommander.Command) JCommander(com.beust.jcommander.JCommander)

Aggregations

JCommander (com.beust.jcommander.JCommander)68 ParameterException (com.beust.jcommander.ParameterException)15 IOException (java.io.IOException)10 Map (java.util.Map)6 ParameterDescription (com.beust.jcommander.ParameterDescription)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 Console (com.beust.jcommander.internal.Console)2 DefaultCommand (com.evolveum.midpoint.cli.common.DefaultCommand)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Charsets (com.google.common.base.Charsets)2 Throwables (com.google.common.base.Throwables)2 HostAndPort (com.google.common.net.HostAndPort)2 Service (com.google.common.util.concurrent.Service)2 CreationException (com.google.inject.CreationException)2 SystemException (com.torodb.core.exceptions.SystemException)2 BackendPasswordConfig (com.torodb.packaging.config.model.backend.BackendPasswordConfig)2 AbstractDerby (com.torodb.packaging.config.model.backend.derby.AbstractDerby)2 AbstractPostgres (com.torodb.packaging.config.model.backend.postgres.AbstractPostgres)2 AbstractReplication (com.torodb.packaging.config.model.protocol.mongo.AbstractReplication)2