Search in sources :

Example 26 with OptionException

use of joptsimple.OptionException in project bitsquare by bitsquare.

the class StatisticsMain method main.

public static void main(String[] args) throws Exception {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Statistics").setDaemon(true).build();
    UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
    // We don't want to do the full argument parsing here as that might easily change in update versions
    // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
    BitsquareEnvironment.setDefaultAppName("Bitsquare_statistics");
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)).withRequiredArg();
    parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)).withRequiredArg();
    OptionSet options;
    try {
        options = parser.parse(args);
    } catch (OptionException ex) {
        System.out.println("error: " + ex.getMessage());
        System.out.println();
        parser.printHelpOn(System.out);
        System.exit(EXIT_FAILURE);
        return;
    }
    BitsquareEnvironment bitsquareEnvironment = new BitsquareEnvironment(options);
    // need to call that before BitsquareAppMain().execute(args)
    BitsquareExecutable.initAppDir(bitsquareEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY));
    // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
    // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
    Thread.currentThread().setContextClassLoader(StatisticsMain.class.getClassLoader());
    new StatisticsMain().execute(args);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) OptionException(joptsimple.OptionException) BitsquareEnvironment(io.bitsquare.app.BitsquareEnvironment) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 27 with OptionException

use of joptsimple.OptionException in project bisq-api by mrosseel.

the class ApiMain method main.

public static void main(String[] args) throws Exception {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("BisqApiMain").setDaemon(true).build();
    UserThread.setExecutor(Executors.newSingleThreadExecutor(threadFactory));
    // We don't want to do the full argument parsing here as that might easily change in update versions
    // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
    BisqEnvironment.setDefaultAppName("bisq_api");
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)).withRequiredArg();
    parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)).withRequiredArg();
    OptionSet options;
    try {
        options = parser.parse(args);
    } catch (OptionException ex) {
        System.out.println("error: " + ex.getMessage());
        System.out.println();
        parser.printHelpOn(System.out);
        System.exit(EXIT_FAILURE);
        return;
    }
    BisqEnvironment bisqEnvironment = getBisqEnvironment(options);
    // need to call that before BisqAppMain().execute(args)
    BisqExecutable.initAppDir(bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY));
    // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
    // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
    Thread.currentThread().setContextClassLoader(ApiMain.class.getClassLoader());
    new ApiMain().execute(args);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) BisqEnvironment(io.bisq.core.app.BisqEnvironment) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 28 with OptionException

use of joptsimple.OptionException in project bisq-api by mrosseel.

the class BisqApiWithUIMain method main.

public static void main(String[] args) throws Exception {
    // We don't want to do the full argument parsing here as that might easily change in update versions
    // So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
    OptionParser parser = new OptionParser();
    parser.allowsUnrecognizedOptions();
    parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, description("User data directory", DEFAULT_USER_DATA_DIR)).withRequiredArg();
    parser.accepts(AppOptionKeys.APP_NAME_KEY, description("Application name", DEFAULT_APP_NAME)).withRequiredArg();
    OptionSet options;
    try {
        options = parser.parse(args);
    } catch (OptionException ex) {
        System.out.println("error: " + ex.getMessage());
        System.out.println();
        parser.printHelpOn(System.out);
        System.exit(EXIT_FAILURE);
        return;
    }
    BisqEnvironment bisqEnvironment = getBisqEnvironment(options);
    // need to call that before bisqAppMain().execute(args)
    initAppDir(bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY));
    // For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
    // In order to work around a bug in JavaFX 8u25 and below, you must include the following code as the first line of your realMain method:
    Thread.currentThread().setContextClassLoader(BisqApiWithUIMain.class.getClassLoader());
    new BisqApiWithUIMain().execute(args);
}
Also used : BisqEnvironment(io.bisq.core.app.BisqEnvironment) OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet) OptionParser(joptsimple.OptionParser)

Example 29 with OptionException

use of joptsimple.OptionException in project divolte-collector by divolte.

the class MappingTestServer method main.

public static void main(final String[] args) throws IOException {
    final MappingTestServerOptionParser parser = new MappingTestServerOptionParser();
    try {
        final OptionSet options = parser.parse(args);
        if (options.has("help")) {
            parser.printHelpOn(System.out);
        } else {
            final String host = options.valueOf(parser.hostOption);
            final Integer port = options.valueOf(parser.portOption);
            final MappingTestServer server = new MappingTestServer(options.valueOf(parser.schemaOption), options.valueOf(parser.mappingOption), port, host);
            Runtime.getRuntime().addShutdownHook(new Thread(server::stopServer));
            log.info("Starting server on {}:{}...", host, port);
            server.runServer();
        }
    } catch (final OptionException e) {
        System.err.println(e.getLocalizedMessage());
        parser.printHelpOn(System.err);
    }
}
Also used : OptionException(joptsimple.OptionException) OptionSet(joptsimple.OptionSet)

Example 30 with OptionException

use of joptsimple.OptionException in project universa by UniversaBlockchain.

the class CLIMain method main.

public static void main(String[] args) throws IOException {
    // when we run untit tests, it is important:
    // args = new String[]{"-c", "/Users/sergeych/dev/new_universa/uniclient-testcreate/simple_root_contract.yml"};
    reporter.clear();
    // it could be called more than once from tests
    keyFiles = null;
    parser = new OptionParser() {

        {
            acceptsAll(asList("?", "h", "help"), "Show help.").forHelp();
            acceptsAll(asList("g", "generate"), "Generate new key pair and store in a files starting " + "with a given prefix.").withRequiredArg().ofType(String.class).describedAs("name_prefix");
            accepts("s", "With -g, specify key strength.").withRequiredArg().ofType(Integer.class).defaultsTo(2048);
            acceptsAll(asList("c", "create"), "Create smart contract from dsl template.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file.yml");
            accepts("wait", "with --register,  wait for network consensus up to specified number of milliseconds.").withOptionalArg().ofType(Integer.class).defaultsTo(5000).describedAs("milliseconds");
            acceptsAll(asList("j", "json"), "Return result in json format.");
            acceptsAll(asList("v", "verbose"), "Provide more detailed information.");
            acceptsAll(asList("network"), "Check network status.");
            accepts("register", "register a specified contract, must be a sealed binary file").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("contract.unicon");
            accepts("tu", "Use with -register. Point to file with your transaction units. " + "Use it to pay for contract's register.").withRequiredArg().ofType(String.class).describedAs("tu.unicon");
            accepts("amount", "Use with -register and -tu. " + "Command is set amount of transaction units will be pay for contract's register.").withRequiredArg().ofType(Integer.class).defaultsTo(1).describedAs("tu amount");
            accepts("tutest", "Use with -register and -tu. Key is point to use test transaction units.");
            accepts("probe", "query the state of the document in the Universa network").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("base64_id");
            acceptsAll(asList("k", "keys"), "List of comma-separated private key files to" + "use to sign contract with, if appropriated.").withRequiredArg().ofType(String.class).withValuesSeparatedBy(",").describedAs("key_file");
            acceptsAll(asList("fingerprints"), "Print fingerprints of keys specified with -k.");
            // acceptsAll(asList("show", "s"), "show contract")
            // .withRequiredArg().ofType(String.class)
            acceptsAll(asList("e", "export"), "Export specified contract. " + "Default export format is JSON. " + "Use '-as' option with values 'json', 'xml' or 'yaml' for export as specified format.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file");
            accepts("as", "Use with -e, --export command. Specify format for export contract. " + "Possible values are 'json', 'xml' or 'yaml'.").withRequiredArg().ofType(String.class).describedAs("format");
            acceptsAll(asList("i", "import"), "Import contract from specified xml, json or yaml file.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file");
            acceptsAll(asList("name", "o"), "Use with -e, --export or -i, --import commands. " + "Specify name of destination file.").withRequiredArg().ofType(String.class).describedAs("filename");
            accepts("extract-key", "Use with -e, --export command. " + "Extracts any public key(s) from specified role into external file.").withRequiredArg().ofType(String.class).describedAs("role");
            accepts("base64", "with --extract-key keys to the text base64 format");
            accepts("get", "Use with -e, --export command. " + "Extracts any field of the contract into external file.").withRequiredArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("field_name");
            accepts("set", "Use with -e, --export command. " + "Specify field of the contract for update. Use -value option to specify value for the field").withRequiredArg().ofType(String.class).describedAs("field_name");
            accepts("value", "Use with -e, --export command and after -set argument. " + "Update specified with -set argument field of the contract.").withRequiredArg().ofType(String.class).describedAs("field_value");
            acceptsAll(asList("f", "find"), "Search all contracts in the specified path including subpaths. " + "Use -r key to check all contracts in the path recursively.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("path");
            acceptsAll(asList("d", "download"), "Download contract from the specified url.").withRequiredArg().ofType(String.class).describedAs("url");
            acceptsAll(asList("ch", "check"), "Check contract for validness. " + "Use -r key to check all contracts in the path recursively.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file/path");
            accepts("r", "Use with --ch, --check or -f, --find commands. " + "Specify to check contracts in the path and do it recursively.");
            // accepts("binary", "Use with --ch, --check. " +
            // "Specify to check contracts from binary data.");
            accepts("term-width").withRequiredArg().ofType(Integer.class).defaultsTo(80);
            accepts("pretty", "Use with -as json option. Make json string pretty.");
            acceptsAll(asList("revoke"), "Revoke specified contract and create a revocation transactional contract. " + "Use -k option to specify private key for revoke contract, " + "key should be same as key you signed contract for revoke with. " + "You cannot revoke contract without pointing private key.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file.unicon");
            acceptsAll(asList("pack-with"), "Pack contract with counterparts (new, revoking). " + "Use -add-sibling option to add sibling and -add-revoke to add revoke item.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file.unicon");
            accepts("add-sibling", "Use with --pack-with command. " + "Option add sibling item for packing contract.").withRequiredArg().ofType(String.class).describedAs("sibling.unicon");
            accepts("add-revoke", "Use with --pack-with command. " + "Option add revoke item for packing contract.").withRequiredArg().ofType(String.class).describedAs("file.unicon");
            acceptsAll(asList("unpack"), "Extracts revoking and new items from contracts and save them.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file.unicon");
            acceptsAll(asList("cost"), "Print cost of operations for contracts with given files of contracts. " + "Can be used as key with -register command.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file");
            accepts("anonymize", "Key erase public key from given contract for role given with -role key and replace " + "it with anonymous id for that public key. If -role key is missed will anonymize all roles. " + "After anonymizing contract will be saved as <file_name>_anonymized.unicon. " + "If you want to save with custom name use -name keys.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("file");
            accepts("role", "Use with -anonymize. Set the role name for anonymizing.").withOptionalArg().withValuesSeparatedBy(",").ofType(String.class).describedAs("role_name");
            accepts("address", "Generate address from key. Path to key define in parameter -address. " + "For generate short address use parameter -short.").withRequiredArg().ofType(String.class).describedAs("file");
            accepts("short", "Generate short addres.");
            accepts("address-match", "Matching address with key from file. Address define in parameter -address-match." + "Path to key define in parameter -keyfile.").withRequiredArg().ofType(String.class).describedAs("file");
            accepts("keyfile", "Path to key for matching with address.").withRequiredArg().ofType(String.class).describedAs("file");
            accepts("folder-match", "Associates the entered address with the key file in the specified directory. Path to directory define in parameter -folder-match. " + "Address define in parameter -addr.").withRequiredArg().ofType(String.class).describedAs("file");
            accepts("addr", "Address for finding key in folder.").withRequiredArg().ofType(String.class).describedAs("address");
        // acceptsAll(asList("ie"), "Test - delete.")
        // .withRequiredArg().ofType(String.class)
        // .describedAs("file");
        }
    };
    try {
        options = parser.parse(args);
        if (options.has("?")) {
            usage(null);
        }
        if (options.has("v")) {
            setVerboseMode(true);
        } else {
            setVerboseMode(false);
        }
        if (options.has("k")) {
            keyFileNames = (List<String>) options.valuesOf("k");
        } else {
            keyFileNames = new ArrayList<>();
            keyFiles = null;
        }
        if (options.has("fingerprints")) {
            printFingerprints();
            finish();
        }
        if (options.has("j")) {
            reporter.setQuiet(true);
        } else {
            reporter.setQuiet(false);
        }
        if (options.has("network")) {
            ClientNetwork n = getClientNetwork();
            int total = n.size();
            n.checkNetworkState(reporter);
            finish();
        }
        if (options.has("register")) {
            doRegister();
        }
        if (options.has("probe")) {
            doProbe();
        }
        if (options.has("g")) {
            doGenerateKeyPair();
            return;
        }
        if (options.has("c")) {
            doCreateContract();
        }
        if (options.has("e")) {
            doExport();
        }
        if (options.has("i")) {
            doImport();
        }
        if (options.has("f")) {
            doFindContracts();
        }
        if (options.has("d")) {
            String source = (String) options.valueOf("d");
            downloadContract(source);
            finish();
        }
        if (options.has("ch")) {
            doCheckContracts();
        }
        if (options.has("revoke")) {
            doRevoke();
        }
        if (options.has("pack-with")) {
            doPackWith();
        }
        if (options.has("unpack")) {
            doUnpackWith();
        }
        if (options.has("cost")) {
            doCost();
        }
        if (options.has("anonymize")) {
            doAnonymize();
        }
        if (options.has("address")) {
            doCreateAddress((String) options.valueOf("address"), options.has("short"));
        }
        if (options.has("address-match")) {
            doAddressMatch((String) options.valueOf("address-match"), (String) options.valueOf("keyfile"));
        }
        if (options.has("folder-match")) {
            doSelectKeyInFolder((String) options.valueOf("folder-match"), (String) options.valueOf("addr"));
        }
        usage(null);
    } catch (OptionException e) {
        if (options != null)
            usage("Unrecognized parameter: " + e.getMessage());
        else
            usage("No options: " + e.getMessage());
    } catch (Finished e) {
        if (reporter.isQuiet())
            System.out.println(reporter.reportJson());
    } catch (Exception e) {
        System.err.println(e.toString());
        // e.printStackTrace();
        usage("Error: " + e.getMessage());
        // usage(e.getMessage());
        System.exit(100);
    }
}
Also used : OptionException(joptsimple.OptionException) OptionParser(joptsimple.OptionParser) BackingStoreException(java.util.prefs.BackingStoreException) OptionException(joptsimple.OptionException)

Aggregations

OptionException (joptsimple.OptionException)41 OptionSet (joptsimple.OptionSet)32 OptionParser (joptsimple.OptionParser)26 File (java.io.File)7 IOException (java.io.IOException)7 List (java.util.List)5 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 ArrayList (java.util.ArrayList)4 BuiltinHelpFormatter (joptsimple.BuiltinHelpFormatter)4 OptionSpec (joptsimple.OptionSpec)4 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)3 ThreadFactory (java.util.concurrent.ThreadFactory)3 BisqEnvironment (io.bisq.core.app.BisqEnvironment)2 BitsquareEnvironment (io.bitsquare.app.BitsquareEnvironment)2 FileInputStream (java.io.FileInputStream)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 Logger (org.slf4j.Logger)2