
io.vertx.groovy.core.cli.CLI.groovy Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.groovy.core.cli;
import groovy.transform.CompileStatic
import io.vertx.lang.groovy.InternalHelper
import io.vertx.core.json.JsonObject
import io.vertx.core.cli.Option
import java.util.List
import io.vertx.core.cli.Argument
/**
* Interface defining a command-line interface (in other words a command such as 'run', 'ls'...).
* This interface is polyglot to ease reuse such as in Vert.x Shell.
*
* A command line interface has a name, and defines a set of options and arguments. Options are key-value pair such
* as -foo=bar
or -flag
. The supported formats depend on the used parser. Arguments are unlike
* options raw values. Options are defined using
* Option, while argument are defined using Argument.
*
* Command line interfaces also define a summary and a description. These attributes are used in the usage generation
* . To disable the help generation, set the hidden
attribute to true
.
*
* Command Line Interface object does not contains "value", it's a model. It must be evaluated by a
* parser that returns a {@link io.vertx.groovy.core.cli.CommandLine} object containing the argument and option values.
*/
@CompileStatic
public class CLI {
private final def io.vertx.core.cli.CLI delegate;
public CLI(Object delegate) {
this.delegate = (io.vertx.core.cli.CLI) delegate;
}
public Object getDelegate() {
return delegate;
}
/**
* Creates an instance of {@link io.vertx.groovy.core.cli.CLI} using the default implementation.
* @param name the name of the CLI (must not be null
)
* @return the created instance of {@link io.vertx.groovy.core.cli.CLI}
*/
public static CLI create(String name) {
def ret= InternalHelper.safeCreate(io.vertx.core.cli.CLI.create(name), io.vertx.groovy.core.cli.CLI.class);
return ret;
}
/**
* Parses the user command line interface and create a new {@link io.vertx.groovy.core.cli.CommandLine} containing extracting values.
* @param arguments the arguments
* @return the creates command line
*/
public CommandLine parse(List arguments) {
def ret= InternalHelper.safeCreate(this.delegate.parse(arguments), io.vertx.groovy.core.cli.CommandLine.class);
return ret;
}
/**
* Parses the user command line interface and create a new {@link io.vertx.groovy.core.cli.CommandLine} containing extracting values.
* @param arguments the arguments
* @param validate enable / disable parsing validation
* @return the creates command line
*/
public CommandLine parse(List arguments, boolean validate) {
def ret= InternalHelper.safeCreate(this.delegate.parse(arguments, validate), io.vertx.groovy.core.cli.CommandLine.class);
return ret;
}
/**
* @return the CLI name.
* @return
*/
public String getName() {
def ret = this.delegate.getName();
return ret;
}
/**
* Sets the name of the CLI.
* @param name the name
* @return the current {@link io.vertx.groovy.core.cli.CLI} instance
*/
public CLI setName(String name) {
this.delegate.setName(name);
return this;
}
/**
* @return the CLI description.
* @return
*/
public String getDescription() {
def ret = this.delegate.getDescription();
return ret;
}
public CLI setDescription(String desc) {
this.delegate.setDescription(desc);
return this;
}
/**
* @return the CLI summary.
* @return
*/
public String getSummary() {
def ret = this.delegate.getSummary();
return ret;
}
/**
* Sets the summary of the CLI.
* @param summary the summary
* @return the current {@link io.vertx.groovy.core.cli.CLI} instance
*/
public CLI setSummary(String summary) {
this.delegate.setSummary(summary);
return this;
}
/**
* Checks whether or not the current {@link io.vertx.groovy.core.cli.CLI} instance is hidden.
* @return true
if the current {@link io.vertx.groovy.core.cli.CLI} is hidden, otherwise
*/
public boolean isHidden() {
def ret = this.delegate.isHidden();
return ret;
}
/**
* Sets whether or not the current instance of {@link io.vertx.groovy.core.cli.CLI} must be hidden. Hidden CLI are not listed when
* displaying usages / help messages. In other words, hidden commands are for power user.
* @param hidden enables or disables the hidden aspect of the CI
* @return the current {@link io.vertx.groovy.core.cli.CLI} instance
*/
public CLI setHidden(boolean hidden) {
this.delegate.setHidden(hidden);
return this;
}
/**
* Gets the list of options.
* @return the list of options, empty if none.
*/
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy