Roberto Sánchez
2014-02-24 f7be2173201d6ef2d559ef4e8fdfef5534eee29e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package net.curisit.securis;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class License {
   private static final Logger log = LoggerFactory.getLogger(License.class);
   public static void main(String[] args) {
       CommandLine cmd = getCommandLine(args);
   }
   private static CommandLine getCommandLine(String[] args) {
       Options ops = prepareOptionCLI();
       if (args.length == 0) {
           printHelp(ops);
       }
       CommandLineParser parser = new PosixParser();
       CommandLine cmd = null;
       try {
           cmd = parser.parse(ops, args);
       } catch (ParseException e) {
           printHelp(ops);
       }
       if (cmd.hasOption('h')) {
           printHelp(ops);
       }
       return cmd;
   }
   private static void printHelp(Options ops) {
       HelpFormatter formatter = new HelpFormatter();
       formatter.printHelp("securis-client", ops, true);
       System.exit(-1);
   }
   @SuppressWarnings("static-access")
   private static Options prepareOptionCLI() {
       Options options = new Options();
       options.addOption("h", "help", false, "Show help.");
       options.addOption(OptionBuilder.withArgName("req_file").withLongOpt("rfile").withDescription("Set request file for its generation or for license requesting.").hasArg(true).create('r'));
       options.addOption(OptionBuilder.withArgName("url_license_server").withLongOpt("server").withDescription("License server url.").hasArg(true).create('s'));
       options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("validate").withDescription("Validate lic file.").hasArg(true).create('l'));
       options.addOption("g", "gen_request", false, "Generate request file. If --rfile parameter is missing then It is generated in current directory.");
       options.addOption("c", "create", false, "Request a license file from server. --rfile and --server parameters are mandatory.");
       options.addOption("t", "test_lc", false, "Test if License Server (LC) is available. --server parameter is mandatory.");
       options.addOption(OptionBuilder.withArgName("lic_file").withLongOpt("sync").withDescription("Synchronize/renew the current license file. --server parameter is mandatory.").hasArg(true).create('y'));
       return options;
   }
}