Class: Warp::Dir::Command
- Defined in:
- lib/warp/dir/command.rb,
lib/warp/dir/command/ls.rb,
lib/warp/dir/command/warp.rb,
lib/warp/dir/command/remove.rb
Defined Under Namespace
Classes: Add, Clean, Help, Install, LS, List, Remove, Warp
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#point ⇒ Object
Returns the value of attribute point.
-
#point_name ⇒ Object
Returns the value of attribute point_name.
-
#point_path ⇒ Object
Returns the value of attribute point_path.
-
#store ⇒ Object
Returns the value of attribute store.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(store, point_name = nil, point_path = nil) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #needs_point? ⇒ Boolean
-
#on(type, &block) ⇒ Object
def chain(another_command) command = Warp::Dir.commander.find(another_command.name) command.new(point_name, point_path).run end.
- #puts(stream, *args) ⇒ Object
Constructor Details
#initialize(store, point_name = nil, point_path = nil) ⇒ Command
Returns a new instance of Command.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
65 66 67 |
# File 'lib/warp/dir/command.rb', line 65 def formatter @formatter end |
#point ⇒ Object
Returns the value of attribute point.
65 66 67 |
# File 'lib/warp/dir/command.rb', line 65 def point @point end |
#point_name ⇒ Object
Returns the value of attribute point_name.
65 66 67 |
# File 'lib/warp/dir/command.rb', line 65 def point_name @point_name end |
#point_path ⇒ Object
Returns the value of attribute point_path.
65 66 67 |
# File 'lib/warp/dir/command.rb', line 65 def point_path @point_path end |
#store ⇒ Object
Returns the value of attribute store.
65 66 67 |
# File 'lib/warp/dir/command.rb', line 65 def store @store end |
Class Method Details
.command_name ⇒ Object
13 14 15 |
# File 'lib/warp/dir/command.rb', line 13 def command_name self.name.gsub(/.*::/, '').downcase.to_sym end |
.help ⇒ Object
17 18 19 20 21 22 23 24 |
# 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) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 |
Instance Method Details
#config ⇒ Object
87 88 89 |
# File 'lib/warp/dir/command.rb', line 87 def config self.store.config end |
#inspect ⇒ Object
102 103 104 |
# File 'lib/warp/dir/command.rb', line 102 def inspect "#{self.class.name}[#{self.command_name}]->(#{self.description})" end |
#needs_point? ⇒ Boolean
106 107 108 |
# File 'lib/warp/dir/command.rb', line 106 def needs_point? false # the default end |
#on(type, &block) ⇒ Object
def chain(another_command)
command = Warp::Dir.commander.find(another_command.name)
command.new(point_name, point_path).run
end
95 96 97 98 99 100 |
# 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) ⇒ Object
110 111 112 113 114 115 116 |
# 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 |