Class: Etna::Command
- Inherits:
-
Object
- Object
- Etna::Command
- Includes:
- CommandOrExecutor
- Defined in:
- lib/etna/command.rb
Direct Known Subclasses
GenerateCompletionScript, EtnaApp::Administrate::Models::ApplyTemplate, EtnaApp::Administrate::Models::Attributes::UpdateFromCsv, EtnaApp::Administrate::Models::CopyTemplate, EtnaApp::Administrate::Project::Create, EtnaApp::Config::Set, EtnaApp::Config::Show, EtnaApp::Console, EtnaApp::CreateTemplate::AttributeActions, EtnaApp::Polyphemus
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #completions ⇒ Object
-
#execute ⇒ Object
To be overridden during inheritance.
- #fill_in_missing_params(args) ⇒ Object
- #find_command(*args, **kwds) ⇒ Object
-
#initialize(parent = nil) ⇒ Command
constructor
A new instance of Command.
-
#setup(config) ⇒ Object
To be overridden during inheritance, to e.g.
Methods included from CommandOrExecutor
#command_name, #completions_for, #desc, #flag_argspec, #flag_as_parameter, included, #parse_flags, #program_name, #usage
Constructor Details
#initialize(parent = nil) ⇒ Command
213 214 215 |
# File 'lib/etna/command.rb', line 213 def initialize(parent = nil) @parent = parent end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
211 212 213 |
# File 'lib/etna/command.rb', line 211 def parent @parent end |
Class Method Details
.parent_scope ⇒ Object
217 218 219 220 221 |
# File 'lib/etna/command.rb', line 217 def self.parent_scope parts = self.name.split('::') parts.pop Kernel.const_get(parts.join('::')) end |
Instance Method Details
#completions ⇒ Object
236 237 238 239 240 241 242 243 244 245 |
# File 'lib/etna/command.rb', line 236 def completions method(:execute).parameters.map do |type, name| name = "..." if name.nil? if type == :req || type == :opt [completions_for(name)] else [] end end.inject([], &:+) end |
#execute ⇒ Object
To be overridden during inheritance.
248 249 250 251 252 253 |
# File 'lib/etna/command.rb', line 248 def execute raise 'Command is not implemented' rescue => e .error(e) raise end |
#fill_in_missing_params(args) ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/etna/command.rb', line 228 def fill_in_missing_params(args) req_params = method(:execute).parameters.select { |type, name| type == :req } args + (req_params[(args.length)..(req_params.length)] || []).map do |type, name| puts "#{name}?" STDIN.gets.chomp end end |
#find_command(*args, **kwds) ⇒ Object
223 224 225 226 |
# File 'lib/etna/command.rb', line 223 def find_command(*args, **kwds) flags, args = parse_flags(*args) [self, args, kwds.update(flags)] end |
#setup(config) ⇒ Object
To be overridden during inheritance, to e.g. connect to a database. Should be called with super by inheriting method.
257 258 259 260 261 262 |
# File 'lib/etna/command.rb', line 257 def setup(config) Etna::Application.find(self.class).configure(config) rescue => e .error(e) raise end |