下面列出了怎么用org.apache.commons.cli2.builder.DefaultOptionBuilder的API类实例代码及写法,或者点击链接到github查看源代码。
protected Command createCommand() {
return new CommandBuilder()
.withName("console")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(new DefaultOptionBuilder()
.withShortName("F")
.withLongName("console-settings")
.withDescription("specifies the console settings file. default is \"" + AbstractApplication.DEFAULT_CONF_FILENAME + "\"")
.withArgument(argFile = new ArgumentBuilder()
.withName("file")
.withMinimum(1)
.withMaximum(1)
.withValidator(FileValidator.getExistingFileInstance())
.create())
.create()
)
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("ls")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optNodeType = new DefaultOptionBuilder()
.withShortName("n")
.withDescription("display the node type of the nodes")
.create())
.withOption(optUUID = new DefaultOptionBuilder()
.withShortName("u")
.withDescription("display the uuid of the referenceable nodes")
.create())
.withOption(optLong = new DefaultOptionBuilder()
.withShortName("l")
.withDescription("combines the flags 'n' and 'u'")
.create())
.withOption(argPath)
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("rm")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("r")
.withDescription("remove the directory artifacts recursively")
.create())
.withOption(argPath = new ArgumentBuilder()
.withName("path")
.withDescription("the jcrfs path")
.withMinimum(1)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("connect")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optForce = new DefaultOptionBuilder()
.withShortName("f")
.withDescription("force reconnect if already connected")
.create())
.withOption(argURI = new ArgumentBuilder()
.withName("rmiuri")
.withDescription("the rmi uri of the repository")
.withMinimum(0)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("proplist")
.withName("pl")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_QUIET)
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("R")
.withLongName("recursive")
.withDescription("descend recursively")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to list the properties from")
.withMinimum(1)
.create())
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("ls")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optTime = new DefaultOptionBuilder()
.withShortName("t")
.withDescription("display the last modification date")
.create())
.withOption(optSize = new DefaultOptionBuilder()
.withShortName("s")
.withDescription("display the file size")
.create())
.withOption(optMime = new DefaultOptionBuilder()
.withShortName("m")
.withDescription("display the mime type")
.create())
.withOption(optLong = new DefaultOptionBuilder()
.withShortName("l")
.withDescription("combines all format flags")
.create())
.withOption(argPath)
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("refresh")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optKeepChanges = new DefaultOptionBuilder()
.withShortName("k")
.withDescription("keep changes")
.create())
.withOption(argJcrPath = new ArgumentBuilder()
.withName("jcr-path")
.withDescription("the jcr path")
.withMinimum(0)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("tree")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("r")
.withDescription("limit depth")
.withArgument(new ArgumentBuilder()
.withName("depth")
.withDescription("limit tree to <depth>")
.withMinimum(1)
.withMaximum(1)
.withValidator(NumberValidator.getIntegerInstance())
.create())
.create())
.withOption(argPath = new ArgumentBuilder()
.withName("path")
.withDescription("the path of the tree")
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("revert")
.withName("rev")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_QUIET)
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("R")
.withLongName("recursive")
.withDescription("descend recursively")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to revert")
.withMinimum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("info")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(OPT_QUIET)
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("R")
.withLongName("recursive")
.withDescription("operate recursive")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to display info")
.withMinimum(0)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("delete")
.withName("del")
.withName("rm")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(OPT_QUIET)
.withOption(optForce = new DefaultOptionBuilder()
.withLongName("force")
.withDescription("force operation to run")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to delete")
.withMinimum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("diff")
.withName("di")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optNonRecursive = new DefaultOptionBuilder()
.withShortName("N")
.withLongName("non-recursive")
.withDescription("operate on single directory")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to display the diffs from")
.withMinimum(0)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("dump")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optConfig = new DefaultOptionBuilder()
.withShortName("c")
.withLongName("config")
.withDescription("writes the config to the local file")
.create())
.withOption(optFilter = new DefaultOptionBuilder()
.withShortName("f")
.withLongName("filter")
.withDescription("writes the workspace filter to the local file")
.create())
.withOption(argPath = new ArgumentBuilder()
.withName("path")
.withDescription("the path")
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("status")
.withName("st")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(optOnlyControlled = new DefaultOptionBuilder()
.withShortName("q")
.withLongName("quiet")
.withDescription("show only status of controlled files")
.create())
.withOption(optShowUpdate = new DefaultOptionBuilder()
.withShortName("u")
.withLongName("show-update")
.withDescription("display update information")
.create())
.withOption(optNonRecursive = new DefaultOptionBuilder()
.withShortName("N")
.withLongName("non-recursive")
.withDescription("operate on single directory")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to display the status")
.withMinimum(0)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("mount")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optForce = new DefaultOptionBuilder()
.withShortName("f")
.withLongName("force")
.withDescription("force remount if already mounted")
.create())
.withOption(optConfigFile = new DefaultOptionBuilder()
.withLongName("file")
.withDescription("config.xml for jcrfs")
.withArgument(new ArgumentBuilder()
.withName("file")
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.withOption(optFilterFile = new DefaultOptionBuilder()
.withLongName("filter")
.withDescription("filter.xml for jcrfs")
.withArgument(new ArgumentBuilder()
.withName("filter")
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.withOption(argPath = new ArgumentBuilder()
.withName("root")
.withDescription("the repository path that forms the mount root")
.withMinimum(0)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("export")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(optType = new DefaultOptionBuilder()
.withShortName("t")
.withDescription("specifies the export type. either 'platform' or 'jar'.")
.withArgument(new ArgumentBuilder()
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.withOption(optPrune = new DefaultOptionBuilder()
.withShortName("P")
.withLongName("prune-missing")
.withDescription("specifies if missing local files should be deleted.")
.create())
.withOption(argJcrPath = new ArgumentBuilder()
.withName("jcr-path")
.withDescription("the jcr path")
.withMinimum(0)
.withMaximum(1)
.create()
)
.withOption(argLocalPath = new ArgumentBuilder()
.withName("local-path")
.withDescription("the local path")
.withMinimum(0)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("propset")
.withName("ps")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_QUIET)
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("R")
.withLongName("recursive")
.withDescription("descend recursively")
.create())
.withOption(argPropName = new ArgumentBuilder()
.withName("propname")
.withDescription("the property name")
.withMinimum(1)
.withMaximum(1)
.create())
.withOption(argPropValue = new ArgumentBuilder()
.withName("propval")
.withDescription("the property value")
.withMinimum(1)
.withMaximum(1)
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to set the property to")
.withMinimum(1)
.create())
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("propget")
.withName("pg")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_QUIET)
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("R")
.withLongName("recursive")
.withDescription("descend recursively")
.create())
.withOption(argPropName = new ArgumentBuilder()
.withName("propname")
.withDescription("the property name")
.withMinimum(1)
.withMaximum(1)
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to get the property from")
.withMinimum(1)
.create())
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("mixins")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optAdd = new DefaultOptionBuilder()
.withShortName("a")
.withLongName("add")
.withDescription("adds a mixin")
.withArgument(new ArgumentBuilder()
.withName("nodetype")
.withMinimum(1)
.create())
.create())
.withOption(optRemove = new DefaultOptionBuilder()
.withShortName("r")
.withLongName("remove")
.withDescription("removes a mixin")
.withArgument(new ArgumentBuilder()
.withName("nodetype")
.withMinimum(1)
.create())
.create())
.withOption(argJcrPath = new ArgumentBuilder()
.withName("jcr-path")
.withDescription("the jcr path")
.withMinimum(1)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("ls")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optType = new DefaultOptionBuilder()
.withShortName("t")
.withDescription("display the artfiact type")
.create())
.withOption(argPath)
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("login")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optCreds = new DefaultOptionBuilder()
.withShortName("c")
.withLongName("credentials")
.withDescription("simple connection credentials")
.withArgument(new ArgumentBuilder()
.withName("user:pass")
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.withOption(optForce = new DefaultOptionBuilder()
.withShortName("f")
.withLongName("force")
.withDescription("force relogin if already logged in")
.create())
.withOption(argWorkspace = new ArgumentBuilder()
.withName("workspace")
.withMinimum(0)
.withMaximum(1)
.create())
.create())
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("commit")
.withName("ci")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(OPT_QUIET)
.withOption(optForce = new DefaultOptionBuilder()
.withLongName("force")
.withDescription("force comitting even if remote is modified")
.create())
.withOption(optNonRecursive = new DefaultOptionBuilder()
.withShortName("N")
.withLongName("non-recursive")
.withDescription("operate on single directory")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to commit")
.withMinimum(0)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("import")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(optSync = new DefaultOptionBuilder()
.withShortName("s")
.withLongName("sync")
.withDescription("put local files under vault control.")
.create())
.withOption(optSysView = new DefaultOptionBuilder()
.withLongName("sysview")
.withDescription("specifies that the indicated local file has the sysview format")
.create())
.withOption(argMountpoint = new ArgumentBuilder()
.withName("uri")
.withDescription("mountpoint uri")
.withMinimum(1)
.withMaximum(1)
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("local-path")
.withDescription("the local path")
.withMinimum(0)
.withMaximum(1)
.create()
)
.withOption(argJcrPath = new ArgumentBuilder()
.withName("jcr-path")
.withDescription("the jcr path")
.withMinimum(0)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
@Override
protected Command createCommand() {
return new CommandBuilder()
.withName("format")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withOption(CliCommand.OPT_VERBOSE)
.withOption(optCheckOnly = new DefaultOptionBuilder()
.withShortName("c")
.withLongName("check-only")
.withDescription("Only check the format.")
.create()
)
.withOption(optPatterns = new DefaultOptionBuilder()
.withShortName("p")
.withLongName("pattern")
.withDescription("pattern for recursive format. defaults to match all xml files.")
.withArgument(new ArgumentBuilder()
.withMinimum(0)
.withConsumeRemaining("**dummy**")
.create())
.create())
.withOption(argPaths = new ArgumentBuilder()
.withName("paths")
.withDescription("files or directories to format.")
.withMinimum(0)
.create()
)
.create())
.create();
}
protected Command createCommand() {
argJcrPath = new ArgumentBuilder()
.withName("jcrPath")
.withDescription("remote path")
.withMinimum(1)
.withMaximum(1)
.create();
argLocalPath = new ArgumentBuilder()
.withName("localPath")
.withDescription("local path (optional)")
.withMinimum(0)
.withMaximum(1)
.create();
return new CommandBuilder()
.withName("checkout")
.withName("co")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optForce = new DefaultOptionBuilder()
.withLongName("force")
.withDescription("force checkout to overwrite local files if they already exist.")
.create())
.withOption(OPT_VERBOSE)
.withOption(OPT_QUIET)
.withOption(argJcrPath)
.withOption(argLocalPath)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("get")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optForce = new DefaultOptionBuilder()
.withShortName("f")
.withDescription("force overwrite if local file already exists")
.create())
.withOption(argJcrPath = new ArgumentBuilder()
.withName("jcrl-path")
.withDescription("the jcr path")
.withMinimum(1)
.withMaximum(1)
.create()
)
.withOption(argLocalPath = new ArgumentBuilder()
.withName("local-path")
.withDescription("the local path")
.withMinimum(0)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("add")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(OPT_QUIET)
.withOption(optNonRecursive = new DefaultOptionBuilder()
.withShortName("N")
.withLongName("non-recursive")
.withDescription("operate on single directory")
.create())
.withOption(optForce = new DefaultOptionBuilder()
.withLongName("force")
.withDescription("force operation to run")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("local file or directory to add")
.withMinimum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("resolved")
.withName("res")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_QUIET)
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("R")
.withLongName("recursive")
.withDescription("descend recursively")
.create())
.withOption(optForce = new DefaultOptionBuilder()
.withLongName("force")
.withDescription("resolve even if contains conflict markers")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to resolve")
.withMinimum(1)
.create()
)
.create()
)
.create();
}
protected Command createCommand() {
return new CommandBuilder()
.withName("update")
.withName("up")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(OPT_VERBOSE)
.withOption(OPT_QUIET)
.withOption(optForce = new DefaultOptionBuilder()
.withLongName("force")
.withDescription("force overwrite of local files")
.create())
.withOption(optNonRecursive = new DefaultOptionBuilder()
.withShortName("N")
.withLongName("non-recursive")
.withDescription("operate on single directory")
.create())
.withOption(argLocalPath = new ArgumentBuilder()
.withName("file")
.withDescription("file or directory to update")
.withMinimum(0)
.create()
)
.create()
)
.create();
}
public static void main(String[] args) throws Exception {
final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
final ArgumentBuilder abuilder = new ArgumentBuilder();
final CommandBuilder cbuilder = new CommandBuilder();
final GroupBuilder gbuilder = new GroupBuilder();
CmdSet set = new CmdSet();
CliHelpFormatter hf = CliHelpFormatter.create();
hf.setCmd(set);
//hf.setHeader("bla bla version vla");
//displayHelp();
//hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
//hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
//hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
//hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
//hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
//hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
//hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
//hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
//hf.getDisplaySettings().add(DisplaySetting.DISPLAY_OPTIONAL);
//hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
//hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
//hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
//hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
//hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
//hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
//hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
//hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
//hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
//hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
//hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
hf.print();
}