Пример #1
0
 /** GoGuiThumbnailer main function. */
 public static void main(String[] args) {
   try {
     String options[] = {
       // "check-expire:", // experimental; needs more testing
       "config:",
       // "expire:", // experimental; needs more testing
       "help",
       "scale",
       "size:",
       "verbose",
       "version"
     };
     Options opt = Options.parse(args, options);
     if (opt.contains("help")) {
       printUsage(System.out);
       return;
     }
     if (opt.contains("version")) {
       System.out.println("GoGuiThumbnailer " + Version.get());
       return;
     }
     /*
     if (opt.contains("expire"))
     {
         int seconds = opt.getInteger("expire", 0, 0);
         ThumbnailUtil.expire(seconds, false);
         return;
     }
     if (opt.contains("check-expire"))
     {
         int seconds = opt.getInteger("expire", 0, 0);
         ThumbnailUtil.expire(seconds, true);
         return;
     } */
     boolean verbose = opt.contains("verbose");
     boolean scale = opt.contains("scale");
     ArrayList<String> arguments = opt.getArguments();
     if (arguments.isEmpty() || arguments.size() > 2) {
       printUsage(System.err);
       System.exit(1);
     }
     File input = new File(arguments.get(0));
     File output = null;
     if (arguments.size() == 2) output = new File(arguments.get(1));
     int size = opt.getInteger("size", 128, 1);
     ThumbnailCreator thumbnailCreator = new ThumbnailCreator(verbose);
     try {
       thumbnailCreator.create(input, output, size, scale);
     } catch (ThumbnailCreator.Error e) {
       System.err.println(e.getMessage());
       System.exit(1);
     }
   } catch (Throwable t) {
     StringUtil.printException(t);
     System.exit(1);
   }
 }
Пример #2
0
 /**
  * Creates a new Options instance from command line. Automatically calls handleConfigOption.
  *
  * @param args The command line split into arguments.
  * @param specs Option specification as in constructor.
  * @return The new Options instance.
  * @throws ErrorMessage If options are not valid according to specs.
  */
 public static Options parse(String[] args, String[] specs) throws ErrorMessage {
   Options opt = new Options(args, specs);
   opt.handleConfigOption();
   return opt;
 }