Module: Vop::CommandSyntax

Defined in:
lib/vop/syntax/command_syntax.rb

Instance Method Summary collapse

Instance Method Details

#allows_extraObject



68
69
70
# File 'lib/vop/syntax/command_syntax.rb', line 68

def allows_extra
  @command.allows_extra = true
end

#block_param(name = "block", options = {}) ⇒ Object

TODO does not really work yet



53
54
55
56
# File 'lib/vop/syntax/command_syntax.rb', line 53

def block_param(name = "block", options = {})
  options.merge! block: true
  param(name, options)
end

#block_param!(name = "block", options = {}) ⇒ Object



58
59
60
61
62
# File 'lib/vop/syntax/command_syntax.rb', line 58

def block_param!(name = "block", options = {})
  options = resolve_options_string(options)
  options.merge! mandatory: true
  block_param(name, options)
end

#contribute(options, &block) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/vop/syntax/command_syntax.rb', line 80

def contribute(options, &block)
  @op.register_contributor(
    command_name: options[:to] || @command.short_name,
    contributor: @command.name
  )
  @command.block = block
end

#description(s) ⇒ Object



9
10
11
# File 'lib/vop/syntax/command_syntax.rb', line 9

def description(s)
  @command.description = s
end

#invalidate(&block) ⇒ Object



88
89
90
# File 'lib/vop/syntax/command_syntax.rb', line 88

def invalidate(&block)
  @command.invalidation_block = block
end

#param(name, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vop/syntax/command_syntax.rb', line 22

def param(name, options = {})
  if name.is_a? Symbol
    key = "name" # default for select_machine
    entity = @op.entities.values.select { |x| x.short_name == name.to_s }.first
    if entity.nil?
      raise "entity #{name.to_s} defined as param in #{@command.name} not found"
    else
      key = entity.key
    end

    options[:entity] = true
    options[:lookup] = lambda do
      list_command_name = name.to_s.carefully_pluralize
      the_list = @op.execute(list_command_name, {})
      the_list.map(&key.to_sym)
    end
    name = name.to_s
  end

  options = resolve_options_string(options)

  @command.add_param(name, options)
end

#param!(name, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/vop/syntax/command_syntax.rb', line 46

def param!(name, options = {})
  options = resolve_options_string(options)
  options.merge! mandatory: true
  param(name, options)
end

#read_onlyObject



64
65
66
# File 'lib/vop/syntax/command_syntax.rb', line 64

def read_only
  @command.read_only = true
end

#resolve_options_string(options) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/vop/syntax/command_syntax.rb', line 13

def resolve_options_string(options)
  if options.is_a? String
    options = {
      description: options
    }
  end
  options
end

#run(&block) ⇒ Object



5
6
7
# File 'lib/vop/syntax/command_syntax.rb', line 5

def run(&block)
  @command.block = block
end

#show(options = {}) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/vop/syntax/command_syntax.rb', line 72

def show(options = {})
  @command.show_options[:columns] = options.delete(:columns)
  @command.show_options[:display_type] = options.delete(:display_type)
  @command.show_options[:sort] = options.delete(:sort)

  raise "unknown keyword #{options.keys.first}" if options.keys.length > 0
end