1 package org.columba.core.main; 19 20 import org.apache.commons.cli.BasicParser; 21 import org.apache.commons.cli.CommandLine; 22 import org.apache.commons.cli.CommandLineParser; 23 import org.apache.commons.cli.HelpFormatter; 24 import org.apache.commons.cli.Option; 25 import org.apache.commons.cli.OptionGroup; 26 import org.apache.commons.cli.Options; 27 import org.apache.commons.cli.ParseException; 28 import org.columba.core.resourceloader.GlobalResourceLoader; 29 30 36 public class ColumbaCmdLineParser { 37 38 private static final String RESOURCE_PATH = "org.columba.core.i18n.global"; 39 40 private CommandLineParser parser; 41 42 private Options options; 43 44 private String [] args; 45 46 private static ColumbaCmdLineParser instance; 47 48 private CommandLine commandLine; 49 50 private boolean restoreLastSession = true; 53 54 private ColumbaCmdLineParser() { 55 parser = new BasicParser(); 56 options = new Options(); 57 } 58 59 64 public static ColumbaCmdLineParser getInstance() { 65 if (instance == null) { 66 instance = new ColumbaCmdLineParser(); 67 } 68 69 return instance; 70 } 71 72 78 public void addOption(Option option) { 79 options.addOption(option); 80 } 81 82 87 public void addOptionGroup(OptionGroup option) { 88 options.addOptionGroup(option); 89 } 90 91 99 public CommandLine parse(String [] args) throws ParseException { 100 commandLine = parser.parse(options, args); 101 102 return commandLine; 103 } 104 105 112 public CommandLine getParsedCommandLine() { 113 return commandLine; 114 } 115 116 119 public void printUsage() { 120 HelpFormatter formatter = new HelpFormatter(); 122 formatter.printHelp(GlobalResourceLoader.getString(RESOURCE_PATH, 123 "global", "cmdline_usage"), options); 124 } 125 126 129 public String [] getArgs() { 130 return args; 131 } 132 133 137 public void setRestoreLastSession(boolean restoreLastSession) { 138 this.restoreLastSession = restoreLastSession; 139 } 140 141 public boolean getRestoreLastSession() { 142 return this.restoreLastSession; 143 } 144 } | Popular Tags |