Package jargs.gnu

Examples of jargs.gnu.CmdLineParser


  final private CmdLineParser.Option filePath;
  final private CmdLineParser.Option frameType;
  final private CmdLineParser.Option exportType;

  public MainProgramArgs(String [] args) {
    parser = new CmdLineParser();
    resource = parser.addStringOption('r', "resource");
    filePath = parser.addStringOption('f', "file");
    frameType = parser.addStringOption('t', "type");
    exportType = parser.addStringOption('x', "export");
        try {
View Full Code Here


    final private CmdLineParser.Option gtrWidth;
    final private CmdLineParser.Option below;
    final private CmdLineParser.Option logcenter;

    public DendroviewArgs(String [] args) {
      parser = new CmdLineParser();
      filePath = parser.addStringOption('o', "output");
      exportType = parser.addStringOption('f', "format");
      scaling = parser.addStringOption('s', "scaling");
      aHeaders = parser.addStringOption('a', "arrayHeaders");
      gHeaders = parser.addStringOption('g', "geneHeaders");
View Full Code Here

public class YUICompressor {

    public static void main(String args[]) {

        CmdLineParser parser = new CmdLineParser();
        CmdLineParser.Option typeOpt = parser.addStringOption("type");
        CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
        CmdLineParser.Option nomungeOpt = parser.addBooleanOption("nomunge");
        CmdLineParser.Option linebreakOpt = parser.addStringOption("line-break");
        CmdLineParser.Option preserveSemiOpt = parser.addBooleanOption("preserve-semi");
        CmdLineParser.Option disableOptimizationsOpt = parser.addBooleanOption("disable-optimizations");
        CmdLineParser.Option helpOpt = parser.addBooleanOption('h', "help");
        CmdLineParser.Option charsetOpt = parser.addStringOption("charset");
        CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o', "output");

        Reader in = null;
        Writer out = null;

        try {

            parser.parse(args);

            Boolean help = (Boolean) parser.getOptionValue(helpOpt);
            if (help != null && help.booleanValue()) {
                usage();
                System.exit(0);
            }

            boolean verbose = parser.getOptionValue(verboseOpt) != null;

            String charset = (String) parser.getOptionValue(charsetOpt);
            if (charset == null || !Charset.isSupported(charset)) {
                // charset = System.getProperty("file.encoding");
                // if (charset == null) {
                //     charset = "UTF-8";
                // }

                // UTF-8 seems to be a better choice than what the system is reporting
                charset = "UTF-8";


                if (verbose) {
                    System.err.println("\n[INFO] Using charset " + charset);
                }
            }

            int linebreakpos = -1;
            String linebreakstr = (String) parser.getOptionValue(linebreakOpt);
            if (linebreakstr != null) {
                try {
                    linebreakpos = Integer.parseInt(linebreakstr, 10);
                } catch (NumberFormatException e) {
                    usage();
                    System.exit(1);
                }
            }

            String type = (String) parser.getOptionValue(typeOpt);
            if (type != null && !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                usage();
                System.exit(1);
            }

            String[] fileArgs = parser.getRemainingArgs();
            java.util.List files = java.util.Arrays.asList(fileArgs);
            if (files.isEmpty()) {
                if (type == null) {
                    usage();
                    System.exit(1);
                }
                files = new java.util.ArrayList();
                files.add("-"); // read from stdin
            }

            String output = (String) parser.getOptionValue(outputFilenameOpt);
            String pattern[] = output != null ? output.split(":") : new String[0];

            java.util.Iterator filenames = files.iterator();
            while(filenames.hasNext()) {
                String inputFilename = (String)filenames.next();

                try {
                    if (inputFilename.equals("-")) {

                        in = new InputStreamReader(System.in, charset);

                    } else {

                        if (type == null) {
                            int idx = inputFilename.lastIndexOf('.');
                            if (idx >= 0 && idx < inputFilename.length() - 1) {
                                type = inputFilename.substring(idx + 1);
                            }
                        }

                        if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                            usage();
                            System.exit(1);
                        }

                        in = new InputStreamReader(new FileInputStream(inputFilename), charset);
                    }

                    String outputFilename = output;
                    // if a substitution pattern was passed in
                    if (pattern.length > 1 && files.size() > 1) {
                        outputFilename = inputFilename.replaceFirst(pattern[0], pattern[1]);
                    }

                    if (type.equalsIgnoreCase("js")) {

                        try {

                            JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {

                                public void warning(String message, String sourceName,
                                        int line, String lineSource, int lineOffset) {
                                    if (line < 0) {
                                        System.err.println("\n[WARNING] " + message);
                                    } else {
                                        System.err.println("\n[WARNING] " + line + ':' + lineOffset + ':' + message);
                                    }
                                }

                                public void error(String message, String sourceName,
                                        int line, String lineSource, int lineOffset) {
                                    if (line < 0) {
                                        System.err.println("\n[ERROR] " + message);
                                    } else {
                                        System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':' + message);
                                    }
                                }

                                public EvaluatorException runtimeError(String message, String sourceName,
                                        int line, String lineSource, int lineOffset) {
                                    error(message, sourceName, line, lineSource, lineOffset);
                                    return new EvaluatorException(message);
                                }
                            });

                            // Close the input stream first, and then open the output stream,
                            // in case the output file should override the input file.
                            in.close(); in = null;

                            if (outputFilename == null) {
                                out = new OutputStreamWriter(System.out, charset);
                            } else {
                                out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
                            }

                            boolean munge = parser.getOptionValue(nomungeOpt) == null;
                            boolean preserveAllSemiColons = parser.getOptionValue(preserveSemiOpt) != null;
                            boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;

                            compressor.compress(out, linebreakpos, munge, verbose,
                                    preserveAllSemiColons, disableOptimizations);

                        } catch (EvaluatorException e) {
View Full Code Here

        System.out.println("\nJSBuilder2 is a JavaScript and CSS project build tool.");
        System.out.println("For additional information, see http://extjs.com/products/jsbuilder/");
    }
   
    private static boolean parseArgs(String[] args) {
        CmdLineParser parser = new CmdLineParser();
        CmdLineParser.Option projectFileOpt = parser.addStringOption('p', "projectFile");
        CmdLineParser.Option homeDirOpt = parser.addStringOption('d', "homeDir");
        CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
        CmdLineParser.Option helpOpt = parser.addBooleanOption('h', "help");       
        CmdLineParser.Option debugSuffixOpt = parser.addStringOption('s', "debugSuffix");       

        try {
            parser.parse(args);
        }
        catch ( CmdLineParser.OptionException e ) {
            System.err.println(e.getMessage());
            System.exit(2);
        }

        homeDir = (String)parser.getOptionValue(homeDirOpt, "");
        projectFile = (String)parser.getOptionValue(projectFileOpt, "");
        debugSuffix = (String)parser.getOptionValue(debugSuffixOpt, "-debug");
        verbose = (Boolean)parser.getOptionValue(verboseOpt, false);
        Boolean help = (Boolean)parser.getOptionValue(helpOpt, false);
        // if help dont proceed
        if (help) {
            return false;
        }
        if (homeDir == "") {
View Full Code Here

        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        Writer out = null;
        Reader in = null;
       
        //initialize command line parser
        CmdLineParser parser = new CmdLineParser();
        CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
        CmdLineParser.Option helpOpt = parser.addBooleanOption('h', "help");
        CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o', "output");
        CmdLineParser.Option nameOpt = parser.addStringOption('n', "name");
        CmdLineParser.Option outputTypeOpt = parser.addStringOption('t', "to");
       
        try {
           
            //parse the arguments
            parser.parse(args);

            //figure out if the help option has been executed
            Boolean help = (Boolean) parser.getOptionValue(helpOpt);
            if (help != null && help.booleanValue()) {
                usage();
                System.exit(0);
            }
           
            //determine boolean options
            verbose = parser.getOptionValue(verboseOpt) != null;           
         
            //get the file arguments
            String[] fileArgs = parser.getRemainingArgs();
            String inputFilename = fileArgs[0];

            if (fileArgs.length == 0) {
                throw new Exception("No input filename specified.");
            }

            in = new InputStreamReader(new FileInputStream(inputFilename), "UTF-8");
            Properties properties = new Properties();
            properties.load(in);

            //get output type
            String outputType = (String) parser.getOptionValue(outputTypeOpt);
            if (outputType == null){
                outputType = "json";
                if (verbose){
                    System.err.println("[INFO] No output type specified, defaulting to json.");
                }
            } else {
                if (verbose){
                    System.err.println("[INFO] Output type set to " + outputType + ".");
                }
            }

            //get output filename
            outputFilename = (String) parser.getOptionValue(outputFilenameOpt);           
            if (outputFilename == null) {
                if (verbose){
                    System.err.println("[INFO] No output file specified, defaulting to stdout.");
                }               
               
                out = new OutputStreamWriter(System.out);
            } else {
                File outputFile = new File(outputFilename);
                if (verbose){
                    System.err.println("[INFO] Output file is '" + outputFile.getAbsolutePath() + "'");
                }
                out = new OutputStreamWriter(bytes, "UTF-8");
            }           

            String name = (String) parser.getOptionValue(nameOpt);
            if (name == null && !outputType.equalsIgnoreCase("json")){
                throw new Exception("Missing --name option.");
            }

            String result = "";
View Full Code Here

    result.append(escapeIndex(dict.get(prefix)));
    return result.toString();
  }

  public static void main(String[] args) {
    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option modeOpt = parser.addStringOption("mode");
    CmdLineParser.Option linebreakOpt = parser.addBooleanOption("line-break");
    CmdLineParser.Option charsetOpt = parser.addStringOption("charset");
    CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o',
        "output");

    Reader in = null;
    Writer out = null;

    try {
      parser.parse(args);
      int mode = 1;
      try {
        mode = Integer.valueOf((String) parser.getOptionValue(modeOpt));
      } catch (Exception e) {
      }
      boolean linebreak = parser.getOptionValue(linebreakOpt) != null;
      String charset = (String) parser.getOptionValue(charsetOpt);
      if (charset == null) {
        charset = System.getProperty("file.encoding");
        if (charset == null) {
          charset = "UTF-8";
        }
      }
      String outputFilename = (String) parser.getOptionValue(outputFilenameOpt);

      String[] fileArgs = parser.getRemainingArgs();
      if (fileArgs.length == 0 || outputFilename == null) {
        System.out.println("参数错误");
        System.exit(1);
      }
View Full Code Here

   */
  public static void main(String[] args) {
    BasicConfigurator.configure(new ConsoleAppender(
      new PatternLayout("%-5p: %m%n")));

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option filename = parser.addStringOption('t', "torrent");
    CmdLineParser.Option create = parser.addBooleanOption('c', "create");
    CmdLineParser.Option announce = parser.addStringOption('a', "announce");

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException oe) {
      System.err.println(oe.getMessage());
      usage(System.err);
      System.exit(1);
    }

    // Display help and exit if requested
    if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
      usage(System.out);
      System.exit(0);
    }

    String filenameValue = (String)parser.getOptionValue(filename);
    if (filenameValue == null) {
      usage(System.err, "Torrent file must be provided!");
      System.exit(1);
    }

    Boolean createFlag = (Boolean)parser.getOptionValue(create);
   
    //For repeated announce urls
    @SuppressWarnings("unchecked")
    Vector<String> announceURLs = (Vector<String>)parser.getOptionValues(announce);
   

    String[] otherArgs = parser.getRemainingArgs();

    if (Boolean.TRUE.equals(createFlag) &&
      (otherArgs.length != 1 || announceURLs.isEmpty())) {
      usage(System.err, "Announce URL and a file or directory must be " +
        "provided to create a torrent file!");
View Full Code Here

   */
  public static void main(String[] args) {
    BasicConfigurator.configure(new ConsoleAppender(
      new PatternLayout("%d [%-25t] %-5p: %m%n")));

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option output = parser.addStringOption('o', "output");
    CmdLineParser.Option iface = parser.addStringOption('i', "iface");
    CmdLineParser.Option seedTime = parser.addIntegerOption('s', "seed");
    CmdLineParser.Option maxUpload = parser.addDoubleOption('u', "max-upload");
    CmdLineParser.Option maxDownload = parser.addDoubleOption('d', "max-download");

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException oe) {
      System.err.println(oe.getMessage());
      usage(System.err);
      System.exit(1);
    }

    // Display help and exit if requested
    if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
      usage(System.out);
      System.exit(0);
    }

    String outputValue = (String)parser.getOptionValue(output,
      DEFAULT_OUTPUT_DIRECTORY);
    String ifaceValue = (String)parser.getOptionValue(iface);
    int seedTimeValue = (Integer)parser.getOptionValue(seedTime, -1);

    double maxDownloadRate = (Double)parser.getOptionValue(maxDownload, 0.0);
    double maxUploadRate = (Double)parser.getOptionValue(maxUpload, 0.0);

    String[] otherArgs = parser.getRemainingArgs();
    if (otherArgs.length != 1) {
      usage(System.err);
      System.exit(1);
    }

View Full Code Here

   */
  public static void main(String[] args) {
    BasicConfigurator.configure(new ConsoleAppender(
      new PatternLayout("%d [%-25t] %-5p: %m%n")));

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option port = parser.addIntegerOption('p', "port");

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException oe) {
      System.err.println(oe.getMessage());
      usage(System.err);
      System.exit(1);
    }

    // Display help and exit if requested
    if (Boolean.TRUE.equals((Boolean)parser.getOptionValue(help))) {
      usage(System.out);
      System.exit(0);
    }

    Integer portValue = (Integer)parser.getOptionValue(port,
      Integer.valueOf(Tracker.DEFAULT_TRACKER_PORT));

    String[] otherArgs = parser.getRemainingArgs();

    if (otherArgs.length > 1) {
      usage(System.err);
      System.exit(1);
    }
View Full Code Here

public class YUICompressor {

    public static void main(String args[]) {

        CmdLineParser parser = new CmdLineParser();
        CmdLineParser.Option typeOpt = parser.addStringOption("type");
        CmdLineParser.Option verboseOpt = parser.addBooleanOption('v', "verbose");
        CmdLineParser.Option nomungeOpt = parser.addBooleanOption("nomunge");
        CmdLineParser.Option linebreakOpt = parser.addStringOption("line-break");
        CmdLineParser.Option preserveSemiOpt = parser.addBooleanOption("preserve-semi");
        CmdLineParser.Option disableOptimizationsOpt = parser.addBooleanOption("disable-optimizations");
        CmdLineParser.Option helpOpt = parser.addBooleanOption('h', "help");
        CmdLineParser.Option charsetOpt = parser.addStringOption("charset");
        CmdLineParser.Option outputFilenameOpt = parser.addStringOption('o', "output");

        Reader in = null;
        Writer out = null;

        try {

            parser.parse(args);

            Boolean help = (Boolean) parser.getOptionValue(helpOpt);
            if (help != null && help.booleanValue()) {
                usage();
                System.exit(0);
            }

            boolean verbose = parser.getOptionValue(verboseOpt) != null;

            String charset = (String) parser.getOptionValue(charsetOpt);
            if (charset == null || !Charset.isSupported(charset)) {
                charset = System.getProperty("file.encoding");
                if (charset == null) {
                    charset = "UTF-8";
                }
                if (verbose) {
                    System.err.println("\n[INFO] Using charset " + charset);
                }
            }

            String[] fileArgs = parser.getRemainingArgs();
            String type = (String) parser.getOptionValue(typeOpt);

            if (fileArgs.length == 0) {

                if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                    usage();
                    System.exit(1);
                }

                in = new InputStreamReader(System.in, charset);

            } else {

                if (type != null && !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                    usage();
                    System.exit(1);
                }

                String inputFilename = fileArgs[0];

                if (type == null) {
                    int idx = inputFilename.lastIndexOf('.');
                    if (idx >= 0 && idx < inputFilename.length() - 1) {
                        type = inputFilename.substring(idx + 1);
                    }
                }

                if (type == null || !type.equalsIgnoreCase("js") && !type.equalsIgnoreCase("css")) {
                    usage();
                    System.exit(1);
                }

                in = new InputStreamReader(new FileInputStream(inputFilename), charset);
            }

            int linebreakpos = -1;
            String linebreakstr = (String) parser.getOptionValue(linebreakOpt);
            if (linebreakstr != null) {
                try {
                    linebreakpos = Integer.parseInt(linebreakstr, 10);
                } catch (NumberFormatException e) {
                    usage();
                    System.exit(1);
                }
            }

            String outputFilename = (String) parser.getOptionValue(outputFilenameOpt);

            if (type.equalsIgnoreCase("js")) {

                try {

                    JavaScriptCompressor compressor = new JavaScriptCompressor(in, new ErrorReporter() {

                        public void warning(String message, String sourceName,
                                int line, String lineSource, int lineOffset) {
                            if (line < 0) {
                                System.err.println("\n[WARNING] " + message);
                            } else {
                                System.err.println("\n[WARNING] " + line + ':' + lineOffset + ':' + message);
                            }
                        }

                        public void error(String message, String sourceName,
                                int line, String lineSource, int lineOffset) {
                            if (line < 0) {
                                System.err.println("\n[ERROR] " + message);
                            } else {
                                System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':' + message);
                            }
                        }

                        public EvaluatorException runtimeError(String message, String sourceName,
                                int line, String lineSource, int lineOffset) {
                            error(message, sourceName, line, lineSource, lineOffset);
                            return new EvaluatorException(message);
                        }
                    });

                    // Close the input stream first, and then open the output stream,
                    // in case the output file should override the input file.
                    in.close(); in = null;

                    if (outputFilename == null) {
                        out = new OutputStreamWriter(System.out, charset);
                    } else {
                        out = new OutputStreamWriter(new FileOutputStream(outputFilename), charset);
                    }

                    boolean munge = parser.getOptionValue(nomungeOpt) == null;
                    boolean preserveAllSemiColons = parser.getOptionValue(preserveSemiOpt) != null;
                    boolean disableOptimizations = parser.getOptionValue(disableOptimizationsOpt) != null;

                    compressor.compress(out, linebreakpos, munge, verbose,
                            preserveAllSemiColons, disableOptimizations);

                } catch (EvaluatorException e) {
View Full Code Here

TOP

Related Classes of jargs.gnu.CmdLineParser

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.