class Warp::Dir::Command
Attributes
formatter[RW]
point[RW]
point_name[RW]
point_path[RW]
store[RW]
Public Class Methods
aliases(*args)
click to toggle source
# File lib/warp/dir/command.rb, line 44 def aliases(*args) if args @aliases << args unless !args || args.empty? @aliases.flatten! end @aliases end
command_name()
click to toggle source
# File lib/warp/dir/command.rb, line 13 def command_name self.name.gsub(/.*::/, '').downcase.to_sym end
description(value = nil)
click to toggle source
# File lib/warp/dir/command.rb, line 39 def description(value = nil) @description = value if value @description end
help()
click to toggle source
# File lib/warp/dir/command.rb, line 17 def help sprintf('%16s %-20s %s%s', self.command_name.to_s.yellow, (self.send(:needs_a_point?) ? '<point>'.cyan : ' '.cyan), self.send(:description).blue.bold, (self.respond_to?(:aliases) && !aliases.empty? ? ", aka: " + aliases.join(', ').blue + '' : '') ) end
inherited(subclass)
click to toggle source
# File lib/warp/dir/command.rb, line 26 def inherited(subclass) ::Warp::Dir::Commander.instance.register(subclass) subclass.class_eval do extend Forwardable def_delegators :@klazz, :command_name, :help, :description end subclass.instance_eval do @description = nil @aliases = [] @needs_a_point = false class << self def description(value = nil) @description = value if value @description end def aliases(*args) if args @aliases << args unless !args || args.empty? @aliases.flatten! end @aliases end def needs_a_point?(value = nil) @needs_a_point = value if value @needs_a_point end end end end
installed_commands()
click to toggle source
# File lib/warp/dir/command.rb, line 60 def installed_commands ::Warp::Dir::Commander.instance.commands end
needs_a_point?(value = nil)
click to toggle source
# File lib/warp/dir/command.rb, line 52 def needs_a_point?(value = nil) @needs_a_point = value if value @needs_a_point end
new(store, point_name = nil, point_path = nil)
click to toggle source
# File lib/warp/dir/command.rb, line 67 def initialize(store, point_name = nil, point_path = nil) @store = store @formatter = ::Warp::Dir::Formatter.new(@store) @klazz = self.class if point_name if point_name.is_a?(::Warp::Dir::Point) self.point = point_name else self.point_name = point_name end self.point_path = point_path if point_path end if store.config.debug require 'pp' STDERR.printf 'Initialized Command: '.yellow.bold pp self end end
Public Instance Methods
config()
click to toggle source
# File lib/warp/dir/command.rb, line 87 def config self.store.config end
inspect()
click to toggle source
# File lib/warp/dir/command.rb, line 102 def inspect "#{self.class.name}[#{self.command_name}]->(#{self.description})" end
needs_point?()
click to toggle source
# File lib/warp/dir/command.rb, line 106 def needs_point? false # the default end
on(type, &block)
click to toggle source
def chain(another_command)
command = Warp::Dir.commander.find(another_command.name) command.new(point_name, point_path).run
end
# File lib/warp/dir/command.rb, line 95 def on(type, &block) this_config = self.store.config ::Warp::Dir.on(type, &block).configure do self.config = this_config end end
puts(stream, *args)
click to toggle source
# File lib/warp/dir/command.rb, line 110 def puts(stream, *args) if store.shell stream.printf("printf \"#{args.join(', ')}\n\"") else stream.printf("#{args.join(', ')}\n") end end