175: def call
176: self.print_header if self.respond_to? :print_header
177:
178:
179: if @b
180: run_validation
181: @b.call(self)
182:
183:
184: elsif !(chosen = find_action(self.option)).empty?
185: raise "Only one action at a time please! I can't #{chosen.join(' AND ')}." if chosen.size > 1
186: criteria = [[@cmd, chosen.first], [chosen.first, @cmd]]
187: meth = name = nil
188:
189: criteria.each do |tuple|
190: name = tuple.join('_')
191: meth = name if self.respond_to?(name)
192: end
193:
194: raise "#{self.class} needs a #{name} method!" unless meth
195:
196: run_validation(meth)
197: self.send(meth)
198:
199:
200: elsif self.respond_to? @cmd.to_sym
201: run_validation(@cmd)
202: self.send(@cmd)
203:
204:
205: else
206: raise "The command #{@alias} has no block and #{self.class} has no #{@cmd} method!"
207: end
208:
209: self.print_footer if respond_to? :print_footer
210: end