Class: Optix::Cli
- Inherits:
-
Object
- Object
- Optix::Cli
- Defined in:
- lib/optix.rb
Direct Known Subclasses
Class Method Summary collapse
- .add_context(key, value, &block) ⇒ Object
- .cli_root(&block) ⇒ Object
- .method_added(meth) ⇒ Object
- .parent(path, label = nil) ⇒ Object
- .rename_to(name) ⇒ Object
Class Method Details
.add_context(key, value, &block) ⇒ Object
277 278 279 280 |
# File 'lib/optix.rb', line 277 def add_context(key, value, &block) @optix_context ||= [] @optix_context << [key, value, block] end |
.cli_root(&block) ⇒ Object
309 310 311 312 313 314 315 |
# File 'lib/optix.rb', line 309 def cli_root(&block) if block add_context(:cli_root, '', &block) else @optix_parent = :none end end |
.method_added(meth) ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/optix.rb', line 317 def method_added(meth) return if @optix_context.nil? @optix_method_name ||= meth.to_s if @optix_parent == :none cmd_path = nil elsif @optix_parent cmd_path = "#{@optix_parent} #{@optix_method_name}" else cmd_path = @optix_method_name end cmd = Optix::command(cmd_path) {} @optix_context.each do |e| if :cli_root == e[0] Optix::command *e[1], &e[2] next end cmd.send(e[0], *e[1], &e[2]) end me = self cmd.send(:exec) do |cmd, opts, argv| self.new.send(meth, cmd, opts, argv) end @optix_parent = '' @optix_method_name = nil @optix_context = nil end |
.parent(path, label = nil) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/optix.rb', line 289 def parent(path, label=nil) @optix_context ||= [] if label label = [label] if label.is_a? String p = path.split (0..p.length-1).each do |i| _path = p[0..i].join(' ') Optix::command(_path) do desc label[i] end end end @optix_parent = path end |
.rename_to(name) ⇒ Object
305 306 307 |
# File 'lib/optix.rb', line 305 def rename_to(name) @optix_method_name = name end |