Class List Method List File List

# Class: Vertx::CLI

Inherits:
  Object
  - Object
  - Vertx::CLI
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb

## Overview

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 Hash, while argument are defined using Hash.

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 CommandLine object containing the argument and option values.

## Class Method Summary (collapse)

- + (::Vertx::CLI) create(name = nil)
  Creates an instance of CLI using the default implementation.

## Instance Method Summary (collapse)

- - (self) add_argument(arg = nil)
  Adds an argument.
- - (self) add_arguments(args = nil)
  Adds a set of arguments.
- - (self) add_option(option = nil)
  Adds an option.
- - (self) add_options(options = nil)
  Adds a set of options.
- - (Hash) get_argument(param_1 = nil)
  Gets an Hash based on its index.
- - (Array<Hash>) get_arguments
  Gets the list of defined arguments.
- - (String) get_description
  @return the CLI description.
- - (String) get_name
  @return the CLI name.
- - (Hash) get_option(name = nil)
  Gets an Hash based on its name (short name, long name or argument name).
- - (Array<Hash>) get_options
  Gets the list of options.
- - (String) get_summary
  @return the CLI summary.
- - (true, false) hidden?
  Checks whether or not the current CLI instance is hidden.
- - (::Vertx::CommandLine) parse(arguments = nil, validate = nil)
  Parses the user command line interface and create a new CommandLine containing extracting values.
- - (self) remove_argument(index = nil)
  Removes an argument identified by its index.
- - (self) remove_option(name = nil)
  Removes an option identified by its name.
- - (self) set_arguments(args = nil)
  Sets the list of arguments.
- - (self) set_description(desc = nil)
- - (self) set_hidden(hidden = nil)
  Sets whether or not the current instance of CLI must be hidden.
- - (self) set_name(name = nil)
  Sets the name of the CLI.
- - (self) set_options(options = nil)
  Sets the list of arguments.
- - (self) set_summary(summary = nil)
  Sets the summary of the CLI.

## Class Method Details

### + (`::Vertx::CLI`) create(name = nil)

Creates an instance of Vertx::CLI using the default implementation.

Parameters:

- name (`String`) (defaults to: `nil`) —
  the name of the CLI (must not be `null`)

Returns:

- (`::Vertx::CLI`) —
  the created instance of Vertx::CLI

Raises:

- (`ArgumentError`)

    32
    33
    34
    35
    36
    37
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 32

    def self.create(name=nil)
      if name.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreCli::CLI.java_method(:create, [Java::java.lang.String.java_class]).call(name),::Vertx::CLI)
      end
      raise ArgumentError, "Invalid arguments when calling create(name)"
    end

## Instance Method Details

### - (`self`) add_argument(arg = nil)

Adds an argument.

Parameters:

- arg (`Hash`) (defaults to: `nil`) —
  the argument, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    172
    173
    174
    175
    176
    177
    178
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 172

    def add_argument(arg=nil)
      if arg.class == Hash && !block_given?
        @j_del.java_method(:addArgument, [Java::IoVertxCoreCli::Argument.java_class]).call(Java::IoVertxCoreCli::Argument.new(::Vertx::Util::Utils.to_json_object(arg)))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_argument(arg)"
    end

### - (`self`) add_arguments(args = nil)

Adds a set of arguments. Unlike #set_arguments, this method does not remove the existing arguments. The given list is appended to the existing list.

Parameters:

- args (`Array<Hash>`) (defaults to: `nil`) —
  the arguments, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    183
    184
    185
    186
    187
    188
    189
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 183

    def add_arguments(args=nil)
      if args.class == Array && !block_given?
        @j_del.java_method(:addArguments, [Java::JavaUtil::List.java_class]).call(args.map { |element| Java::IoVertxCoreCli::Argument.new(::Vertx::Util::Utils.to_json_object(element)) })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_arguments(args)"
    end

### - (`self`) add_option(option = nil)

Adds an option.

Parameters:

- option (`Hash`) (defaults to: `nil`) —
  the option, must not be `null`.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    133
    134
    135
    136
    137
    138
    139
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 133

    def add_option(option=nil)
      if option.class == Hash && !block_given?
        @j_del.java_method(:addOption, [Java::IoVertxCoreCli::Option.java_class]).call(Java::IoVertxCoreCli::Option.new(::Vertx::Util::Utils.to_json_object(option)))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_option(option)"
    end

### - (`self`) add_options(options = nil)

Adds a set of options. Unlike #set_options}, this method does not remove the existing options. The given list is appended to the existing list.

Parameters:

- options (`Array<Hash>`) (defaults to: `nil`) —
  the options, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    144
    145
    146
    147
    148
    149
    150
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 144

    def add_options(options=nil)
      if options.class == Array && !block_given?
        @j_del.java_method(:addOptions, [Java::JavaUtil::List.java_class]).call(options.map { |element| Java::IoVertxCoreCli::Option.new(::Vertx::Util::Utils.to_json_object(element)) })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_options(options)"
    end

### - (`Hash`) getArgument(name) - (`Hash`) getArgument(index)

Gets an Hash based on its index.

Overloads:

- - (`Hash`) getArgument(name)

  Parameters:

  - name (`String`) —
    the name of the argument, must not be `null`
- - (`Hash`) getArgument(index)

  Parameters:

  - index (`Fixnum`) —
    the index, must be positive or zero.

Returns:

- (`Hash`) —
  the Hash, `null` if not found.

Raises:

- (`ArgumentError`)

    215
    216
    217
    218
    219
    220
    221
    222
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 215

    def get_argument(param_1=nil)
      if param_1.class == String && !block_given?
        return @j_del.java_method(:getArgument, [Java::java.lang.String.java_class]).call(param_1) != nil ? JSON.parse(@j_del.java_method(:getArgument, [Java::java.lang.String.java_class]).call(param_1).toJson.encode) : nil
      elsif param_1.class == Fixnum && !block_given?
        return @j_del.java_method(:getArgument, [Java::int.java_class]).call(param_1) != nil ? JSON.parse(@j_del.java_method(:getArgument, [Java::int.java_class]).call(param_1).toJson.encode) : nil
      end
      raise ArgumentError, "Invalid arguments when calling get_argument(param_1)"
    end

### - (`Array<Hash>`) get_arguments

Gets the list of defined arguments.

Returns:

- (`Array<Hash>`) —
  the list of argument, empty if none.

Raises:

- (`ArgumentError`)

    163
    164
    165
    166
    167
    168
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 163

    def get_arguments
      if !block_given?
        return @j_del.java_method(:getArguments, []).call().to_a.map { |elt| elt != nil ? JSON.parse(elt.toJson.encode) : nil }
      end
      raise ArgumentError, "Invalid arguments when calling get_arguments()"
    end

### - (`String`) get_description

@return the CLI description.

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    70
    71
    72
    73
    74
    75
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 70

    def get_description
      if !block_given?
        return @j_del.java_method(:getDescription, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling get_description()"
    end

### - (`String`) get_name

@return the CLI name.

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    52
    53
    54
    55
    56
    57
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 52

    def get_name
      if !block_given?
        return @j_del.java_method(:getName, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling get_name()"
    end

### - (`Hash`) get_option(name = nil)

Gets an Hash based on its name (short name, long name or argument name).

Parameters:

- name (`String`) (defaults to: `nil`) —
  the name, must not be `null`

Returns:

- (`Hash`) —
  the Hash, `null` if not found

Raises:

- (`ArgumentError`)

    203
    204
    205
    206
    207
    208
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 203

    def get_option(name=nil)
      if name.class == String && !block_given?
        return @j_del.java_method(:getOption, [Java::java.lang.String.java_class]).call(name) != nil ? JSON.parse(@j_del.java_method(:getOption, [Java::java.lang.String.java_class]).call(name).toJson.encode) : nil
      end
      raise ArgumentError, "Invalid arguments when calling get_option(name)"
    end

### - (`Array<Hash>`) get_options

Gets the list of options.

Returns:

- (`Array<Hash>`) —
  the list of options, empty if none.

Raises:

- (`ArgumentError`)

    124
    125
    126
    127
    128
    129
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 124

    def get_options
      if !block_given?
        return @j_del.java_method(:getOptions, []).call().to_a.map { |elt| elt != nil ? JSON.parse(elt.toJson.encode) : nil }
      end
      raise ArgumentError, "Invalid arguments when calling get_options()"
    end

### - (`String`) get_summary

@return the CLI summary.

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    87
    88
    89
    90
    91
    92
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 87

    def get_summary
      if !block_given?
        return @j_del.java_method(:getSummary, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling get_summary()"
    end

### - (`true`, `false`) hidden?

Checks whether or not the current Vertx::CLI instance is hidden.

Returns:

- (`true`, `false`) —
  `true` if the current Vertx::CLI is hidden, otherwise

Raises:

- (`ArgumentError`)

    105
    106
    107
    108
    109
    110
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 105

    def hidden?
      if !block_given?
        return @j_del.java_method(:isHidden, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling hidden?()"
    end

### - (`::Vertx::CommandLine`) parse(arguments = nil, validate = nil)

Parses the user command line interface and create a new Vertx::CommandLine containing extracting values.

Parameters:

- arguments (`Array<String>`) (defaults to: `nil`) —
  the arguments
- validate (`true`, `false`) (defaults to: `nil`) —
  enable / disable parsing validation

Returns:

- (`::Vertx::CommandLine`) —
  the creates command line

Raises:

- (`ArgumentError`)

    42
    43
    44
    45
    46
    47
    48
    49
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 42

    def parse(arguments=nil,validate=nil)
      if arguments.class == Array && !block_given? && validate == nil
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:parse, [Java::JavaUtil::List.java_class]).call(arguments.map { |element| element }),::Vertx::CommandLine)
      elsif arguments.class == Array && (validate.class == TrueClass || validate.class == FalseClass) && !block_given?
        return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:parse, [Java::JavaUtil::List.java_class,Java::boolean.java_class]).call(arguments.map { |element| element },validate),::Vertx::CommandLine)
      end
      raise ArgumentError, "Invalid arguments when calling parse(arguments,validate)"
    end

### - (`self`) remove_argument(index = nil)

Removes an argument identified by its index. This method does nothing if the argument cannot be found.

Parameters:

- index (`Fixnum`) (defaults to: `nil`) —
  the argument index

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    236
    237
    238
    239
    240
    241
    242
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 236

    def remove_argument(index=nil)
      if index.class == Fixnum && !block_given?
        @j_del.java_method(:removeArgument, [Java::int.java_class]).call(index)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling remove_argument(index)"
    end

### - (`self`) remove_option(name = nil)

Removes an option identified by its name. This method does nothing if the option cannot be found.

Parameters:

- name (`String`) (defaults to: `nil`) —
  the option name

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    226
    227
    228
    229
    230
    231
    232
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 226

    def remove_option(name=nil)
      if name.class == String && !block_given?
        @j_del.java_method(:removeOption, [Java::java.lang.String.java_class]).call(name)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling remove_option(name)"
    end

### - (`self`) set_arguments(args = nil)

Sets the list of arguments.

Parameters:

- args (`Array<Hash>`) (defaults to: `nil`) —
  the list of arguments, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    193
    194
    195
    196
    197
    198
    199
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 193

    def set_arguments(args=nil)
      if args.class == Array && !block_given?
        @j_del.java_method(:setArguments, [Java::JavaUtil::List.java_class]).call(args.map { |element| Java::IoVertxCoreCli::Argument.new(::Vertx::Util::Utils.to_json_object(element)) })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_arguments(args)"
    end

### - (`self`) set_description(desc = nil)

Parameters:

- desc (`String`) (defaults to: `nil`)

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    78
    79
    80
    81
    82
    83
    84
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 78

    def set_description(desc=nil)
      if desc.class == String && !block_given?
        @j_del.java_method(:setDescription, [Java::java.lang.String.java_class]).call(desc)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_description(desc)"
    end

### - (`self`) set_hidden(hidden = nil)

Sets whether or not the current instance of Vertx::CLI must be hidden. Hidden CLI are not listed when displaying usages / help messages. In other words, hidden commands are for power user.

Parameters:

- hidden (`true`, `false`) (defaults to: `nil`) —
  enables or disables the hidden aspect of the CI

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    115
    116
    117
    118
    119
    120
    121
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 115

    def set_hidden(hidden=nil)
      if (hidden.class == TrueClass || hidden.class == FalseClass) && !block_given?
        @j_del.java_method(:setHidden, [Java::boolean.java_class]).call(hidden)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_hidden(hidden)"
    end

### - (`self`) set_name(name = nil)

Sets the name of the CLI.

Parameters:

- name (`String`) (defaults to: `nil`) —
  the name

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    61
    62
    63
    64
    65
    66
    67
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 61

    def set_name(name=nil)
      if name.class == String && !block_given?
        @j_del.java_method(:setName, [Java::java.lang.String.java_class]).call(name)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_name(name)"
    end

### - (`self`) set_options(options = nil)

Sets the list of arguments.

Parameters:

- options (`Array<Hash>`) (defaults to: `nil`) —
  the list of options, must not be `null`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    154
    155
    156
    157
    158
    159
    160
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 154

    def set_options(options=nil)
      if options.class == Array && !block_given?
        @j_del.java_method(:setOptions, [Java::JavaUtil::List.java_class]).call(options.map { |element| Java::IoVertxCoreCli::Option.new(::Vertx::Util::Utils.to_json_object(element)) })
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_options(options)"
    end

### - (`self`) set_summary(summary = nil)

Sets the summary of the CLI.

Parameters:

- summary (`String`) (defaults to: `nil`) —
  the summary

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    96
    97
    98
    99
    100
    101
    102
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx/cli.rb', line 96

    def set_summary(summary=nil)
      if summary.class == String && !block_given?
        @j_del.java_method(:setSummary, [Java::java.lang.String.java_class]).call(summary)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling set_summary(summary)"
    end