Class: Nucleon::Plugin::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/core/plugin/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_idsObject



6
7
8
# File 'lib/core/plugin/command.rb', line 6

def self.register_ids
  [ :command, :args, :flags, :data, :subcommand ]
end

Instance Method Details

#args(default = []) ⇒ Object




38
39
40
# File 'lib/core/plugin/command.rb', line 38

def args(default = [])
  return array(get(:args, default)) 
end

#args=(args) ⇒ Object




44
45
46
# File 'lib/core/plugin/command.rb', line 44

def args=args
  set(:args, array(args))
end

#build(components = {}, overrides = nil, override_key = false) ⇒ Object


Command operations



83
84
85
86
87
88
89
# File 'lib/core/plugin/command.rb', line 83

def build(components = {}, overrides = nil, override_key = false)
  logger.debug("Building command with #{components.inspect}")
  logger.debug("Overrides: #{overrides.inspect}")
  logger.debug("Override key: #{override_key}")
  
  return '' # Implement in sub classes
end

#command(default = '') ⇒ Object


Property accessor / modifiers



26
27
28
# File 'lib/core/plugin/command.rb', line 26

def command(default = '')
  return string(get(:command, default))
end

#command=(command) ⇒ Object




32
33
34
# File 'lib/core/plugin/command.rb', line 32

def command=command
  set(:command, string(command))
end

#data(default = {}) ⇒ Object




62
63
64
# File 'lib/core/plugin/command.rb', line 62

def data(default = {})
  return hash(get(:data, default)) 
end

#data=(data) ⇒ Object




68
69
70
# File 'lib/core/plugin/command.rb', line 68

def data=data
  set(:data, hash(data))
end

#exec(options = {}, overrides = nil) ⇒ Object




93
94
95
96
97
98
99
# File 'lib/core/plugin/command.rb', line 93

def exec(options = {}, overrides = nil)
  logger.debug("Executing command with #{options.inspect}")
  logger.debug("Overrides: #{overrides.inspect}")
  
  # Implement in sub classes (don't forget the yield!)
  return true
end

#flags(default = []) ⇒ Object




50
51
52
# File 'lib/core/plugin/command.rb', line 50

def flags(default = [])
  return array(get(:flags, default)) 
end

#flags=(flags) ⇒ Object




56
57
58
# File 'lib/core/plugin/command.rb', line 56

def flags=flags
  set(:flags, array(flags))
end

#normalize(reload) ⇒ Object


Command plugin interface



13
14
15
# File 'lib/core/plugin/command.rb', line 13

def normalize(reload)
  super
end

#subcommand=(subcommand) ⇒ Object




74
75
76
77
78
# File 'lib/core/plugin/command.rb', line 74

def subcommand=subcommand
  unless Util::Data.empty?(subcommand)
    set(:subcommand, new(hash(subcommand)))
  end
end

#to_sObject




19
20
21
# File 'lib/core/plugin/command.rb', line 19

def to_s
  return build(export)
end