Module: Vop::CommandSyntax
- Defined in:
- lib/vop/syntax/command_syntax.rb
Instance Method Summary collapse
- #allows_extra ⇒ Object
-
#block_param(name = "block", options = {}) ⇒ Object
TODO does not really work yet.
- #block_param!(name = "block", options = {}) ⇒ Object
- #contribute(options, &block) ⇒ Object
- #description(s) ⇒ Object
- #invalidate(&block) ⇒ Object
- #param(name, options = {}) ⇒ Object
- #param!(name, options = {}) ⇒ Object
- #read_only ⇒ Object
- #resolve_options_string(options) ⇒ Object
- #run(&block) ⇒ Object
- #show(options = {}) ⇒ Object
Instance Method Details
#allows_extra ⇒ Object
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", = {}) .merge! block: true param(name, ) 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", = {}) = () .merge! mandatory: true block_param(name, ) end |
#contribute(options, &block) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/vop/syntax/command_syntax.rb', line 80 def contribute(, &block) @op.register_contributor( command_name: [: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, = {}) 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 [:entity] = true [: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 = () @command.add_param(name, ) end |
#param!(name, options = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/vop/syntax/command_syntax.rb', line 46 def param!(name, = {}) = () .merge! mandatory: true param(name, ) end |
#read_only ⇒ Object
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 () if .is_a? String = { description: } end 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( = {}) @command.[:columns] = .delete(:columns) @command.[:display_type] = .delete(:display_type) @command.[:sort] = .delete(:sort) raise "unknown keyword #{.keys.first}" if .keys.length > 0 end |