All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.groovy.core.cli.CommandLine.groovy Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
/*
 * 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
/**
 * The parser transforms a CLI (a model) into an {@link io.vertx.groovy.core.cli.CommandLine}. This {@link io.vertx.groovy.core.cli.CommandLine}
 * has stored the argument and option values. Only  instance of parser should create
 * objects of this type.
*/
@CompileStatic
public class CommandLine {
  private final def io.vertx.core.cli.CommandLine delegate;
  public CommandLine(Object delegate) {
    this.delegate = (io.vertx.core.cli.CommandLine) delegate;
  }
  public Object getDelegate() {
    return delegate;
  }
  /**
   * Creates a command line object from the {@link io.vertx.groovy.core.cli.CLI}. This object is intended to be used by
   * the parser to set the argument and option values.
   * @param cli the CLI definition
   * @return the command line object
   */
  public static CommandLine create(CLI cli) {
    def ret= InternalHelper.safeCreate(io.vertx.core.cli.CommandLine.create((io.vertx.core.cli.CLI)cli.getDelegate()), io.vertx.groovy.core.cli.CommandLine.class);
    return ret;
  }
  /**
   * @return the model of this command line object.
   * @return 
   */
  public CLI cli() {
    def ret= InternalHelper.safeCreate(this.delegate.cli(), io.vertx.groovy.core.cli.CLI.class);
    return ret;
  }
  /**
   * @return the ordered list of arguments. Arguments are command line arguments not matching an option.
   * @return 
   */
  public List allArguments() {
    def ret = this.delegate.allArguments();
    return ret;
  }
  /**
   * Gets the value of an option with the matching name (can be the long name, short name or arg name).
   * @param name the name
   * @return the value, null if not set
   */
  public  T getOptionValue(String name) {
    // This cast is cleary flawed
    def ret = (T) InternalHelper.wrapObject(this.delegate.getOptionValue(name));
    return ret;
  }
  /**
   * Gets the value of an argument with the matching name (arg name).
   * @param name the name
   * @return the value, null if not set
   */
  public  T getArgumentValue(String name) {
    // This cast is cleary flawed
    def ret = (T) InternalHelper.wrapObject(this.delegate.getArgumentValue(name));
    return ret;
  }
  /**
   * Gets the value of an argument with the given index.
   * @param index the index
   * @return the value, null if not set
   */
  public  T getArgumentValue(int index) {
    // This cast is cleary flawed
    def ret = (T) InternalHelper.wrapObject(this.delegate.getArgumentValue(index));
    return ret;
  }
  /**
   * Gets the value of an option marked as a flag.
   * 

* Calling this method an a non-flag option throws an {@link java.lang.IllegalStateException}. * @param name the option name * @return true if the flag has been set in the command line, false otherwise. */ public boolean isFlagEnabled(String name) { def ret = this.delegate.isFlagEnabled(name); return ret; } /** * Checks whether or not the given option has been assigned in the command line. * @param option the option (see Option) * @return true if the option has received a value, otherwise. */ public boolean isOptionAssigned(Map option = [:]) { def ret = this.delegate.isOptionAssigned(option != null ? new io.vertx.core.cli.Option(new io.vertx.core.json.JsonObject(option)) : null); return ret; } /** * Gets the raw values of the given option. Raw values are simple "String", not converted to the option type. * @param option the option (see Option) * @return the list of values, empty if none */ public List getRawValues(Map option = [:]) { def ret = this.delegate.getRawValues(option != null ? new io.vertx.core.cli.Option(new io.vertx.core.json.JsonObject(option)) : null); return ret; } /** * Gets the raw values of the given option. Raw values are simple "String", not converted to the option type. * @param option the option (see Option) * @return the list of values, empty if none */ public List getRawValuesForOption(Map option = [:]) { def ret = this.delegate.getRawValuesForOption(option != null ? new io.vertx.core.cli.Option(new io.vertx.core.json.JsonObject(option)) : null); return ret; } /** * Gets the raw values of the given argument. Raw values are simple "String", not converted to the argument type. * @param argument the argument (see Argument) * @return the list of values, empty if none */ public List getRawValuesForArgument(Map argument = [:]) { def ret = this.delegate.getRawValuesForArgument(argument != null ? new io.vertx.core.cli.Argument(new io.vertx.core.json.JsonObject(argument)) : null); return ret; } /** * Gets the raw value of the given option. Raw values are the values as given in the user command line. * @param option the option (see Option) * @return the value, null if none. */ public String getRawValueForOption(Map option = [:]) { def ret = this.delegate.getRawValueForOption(option != null ? new io.vertx.core.cli.Option(new io.vertx.core.json.JsonObject(option)) : null); return ret; } /** * Checks whether or not the given option accept more values. * @param option the option (see Option) * @return if the option accepts more values, otherwise. */ public boolean acceptMoreValues(Map option = [:]) { def ret = this.delegate.acceptMoreValues(option != null ? new io.vertx.core.cli.Option(new io.vertx.core.json.JsonObject(option)) : null); return ret; } /** * Gets the raw value of the given argument. Raw values are the values as given in the user command line. * @param arg the argument (see Argument) * @return the value, null if none. */ public String getRawValueForArgument(Map arg = [:]) { def ret = this.delegate.getRawValueForArgument(arg != null ? new io.vertx.core.cli.Argument(new io.vertx.core.json.JsonObject(arg)) : null); return ret; } /** * Checks whether or not the given argument has been assigned in the command line. * @param arg the argument (see Argument) * @return true if the argument has received a value, otherwise. */ public boolean isArgumentAssigned(Map arg = [:]) { def ret = this.delegate.isArgumentAssigned(arg != null ? new io.vertx.core.cli.Argument(new io.vertx.core.json.JsonObject(arg)) : null); return ret; } /** * Checks whether or not the given option has been seen in the user command line. * @param option the option (see Option) * @return true if the user command line has used the option */ public boolean isSeenInCommandLine(Map option = [:]) { def ret = this.delegate.isSeenInCommandLine(option != null ? new io.vertx.core.cli.Option(new io.vertx.core.json.JsonObject(option)) : null); return ret; } /** * Checks whether or not the command line is valid, i.e. all constraints from arguments and options have been * satisfied. This method is used when the parser validation is disabled. * @return true if the current {@link io.vertx.groovy.core.cli.CommandLine} object is valid. otherwise. */ public boolean isValid() { def ret = this.delegate.isValid(); return ret; } /** * Checks whether or not the user has passed a "help" option and is asking for help. * @return true if the user command line has enabled a "Help" option, otherwise. */ public boolean isAskingForHelp() { def ret = this.delegate.isAskingForHelp(); return ret; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy