Class: Vertx::CLI

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/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.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


30
31
32
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 30

def @@j_api_type.accept?(obj)
  obj.class == CLI
end

+ (::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:

Raises:

  • (ArgumentError)


48
49
50
51
52
53
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 48

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

+ (Object) j_api_type



39
40
41
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 39

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



42
43
44
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 42

def self.j_class
  Java::IoVertxCoreCli::CLI.java_class
end

+ (Object) unwrap(obj)



36
37
38
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 36

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



33
34
35
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 33

def @@j_api_type.wrap(obj)
  CLI.new(obj)
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)


185
186
187
188
189
190
191
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 185

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)


196
197
198
199
200
201
202
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 196

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)


146
147
148
149
150
151
152
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 146

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)


157
158
159
160
161
162
163
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 157

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)


228
229
230
231
232
233
234
235
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 228

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)


176
177
178
179
180
181
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 176

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

Returns the CLI description.

Returns:

  • (String)
    the CLI description.

Raises:

  • (ArgumentError)


84
85
86
87
88
89
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 84

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

Returns the CLI name.

Returns:

  • (String)
    the CLI name.

Raises:

  • (ArgumentError)


67
68
69
70
71
72
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 67

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)


216
217
218
219
220
221
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 216

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)


137
138
139
140
141
142
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 137

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

Returns the CLI summary.

Returns:

  • (String)
    the CLI summary.

Raises:

  • (ArgumentError)


100
101
102
103
104
105
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 100

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)


118
119
120
121
122
123
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 118

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:

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 58

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)


249
250
251
252
253
254
255
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 249

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)


239
240
241
242
243
244
245
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 239

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)


206
207
208
209
210
211
212
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 206

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)


92
93
94
95
96
97
98
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 92

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)


128
129
130
131
132
133
134
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 128

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)


76
77
78
79
80
81
82
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 76

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)


167
168
169
170
171
172
173
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 167

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)


109
110
111
112
113
114
115
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/cli.rb', line 109

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