import com.github.optparse4j.Command; import com.github.optparse4j.OptionParser; import com.github.optparse4j.OptionSet; public class MyCommand { public static void main(String[] args) { OptionParser optionParser = new OptionParser(); Command myCommand = optionParser.addCommand("myCommand"); myCommand.accepts("option1").withOptionalArg(); myCommand.accepts("option2").withRequiredArg(); myCommand.accepts("flag").withOptionalArg().ofType(Boolean.class).describedAs("A flag option"); OptionSet optionSet = optionParser.parse(args); if (optionSet.has("option1")) { } if (optionSet.has("option2")) { String option2Value = (String) optionSet.valueOf("option2"); } if (optionSet.has("flag")) { Boolean flagValue = (Boolean) optionSet.valueOf("flag"); } } }


上一篇:
下一篇:
切换中文