Parent

Thor::Shell::Basic

Attributes

base[RW]

(Not documented)

padding[RW]

(Not documented)

Public Instance Methods

ask(statement, color=nil) click to toggle source

Ask something to the user and receives a response.

Example

ask(“What is your name?”)

    # File lib/thor/shell/basic.rb, line 25
25:       def ask(statement, color=nil)
26:         say("#{statement} ", color)
27:         $stdin.gets.strip
28:       end
error(statement) click to toggle source

Called if something goes wrong during the execution. This is used by Thor internally and should not be used inside your scripts. If someone went wrong, you can always raise an exception. If you raise a Thor::Error, it will be rescued and wrapped in the method below.

     # File lib/thor/shell/basic.rb, line 169
169:       def error(statement)
170:         $stderr.puts statement
171:       end
file_collision(destination) click to toggle source

Deals with file collision and returns true if the file should be overwriten and false otherwise. If a block is given, it uses the block response as the content for the diff.

Parameters

destination:the destination file to solve conflicts
block:an optional block that returns the value to be used in diff
     # File lib/thor/shell/basic.rb, line 138
138:       def file_collision(destination)
139:         return true if @always_force
140:         options = block_given? ? "[Ynaqdh]" : "[Ynaqh]"
141: 
142:         while true
143:           answer = ask %[Overwrite #{destination}? (enter "h" for help) #{options}]
144: 
145:           case answer
146:             when is?(:yes), is?(:force)
147:               return true
148:             when is?(:no), is?(:skip)
149:               return false
150:             when is?(:always)
151:               return @always_force = true
152:             when is?(:quit)
153:               say 'Aborting...'
154:               raise SystemExit
155:             when is?(:diff)
156:               show_diff(destination, yield) if block_given?
157:               say 'Retrying...'
158:             else
159:               say file_collision_help
160:           end
161:         end
162:       end
no?(statement, color=nil) click to toggle source

Make a question the to user and returns true if the user replies “n” or “no”.

    # File lib/thor/shell/basic.rb, line 74
74:       def no?(statement, color=nil)
75:         !yes?(statement, color)
76:       end
padding=(value) click to toggle source

Sets the output padding, not allowing less than zero values.

    # File lib/thor/shell/basic.rb, line 16
16:       def padding=(value)
17:         @padding = [0, value].max
18:       end
say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)$/)) click to toggle source

Say (print) something to the user. If the sentence ends with a whitespace or tab character, a new line is not appended (print + flush). Otherwise are passed straight to puts (behavior got from Highline).

Example

say(“I know you knew that.”)

    # File lib/thor/shell/basic.rb, line 37
37:       def say(message="", color=nil, force_new_line=(message.to_s !~ /( |\t)$/))
38:         message  = message.to_s
39:         message  = set_color(message, color) if color
40: 
41:         if force_new_line
42:           $stdout.puts(message)
43:         else
44:           $stdout.print(message)
45:           $stdout.flush
46:         end
47:       end
say_status(status, message, log_status=true) click to toggle source

Say a status with the given color and appends the message. Since this method is used frequently by actions, it allows nil or false to be given in log_status, avoiding the message from being shown. If a Symbol is given in log_status, it’s used as the color.

    # File lib/thor/shell/basic.rb, line 54
54:       def say_status(status, message, log_status=true)
55:         return if quiet? || log_status == false
56:         spaces = "  " * (padding + 1)
57:         color  = log_status.is_a?(Symbol) ? log_status : :green
58: 
59:         status = status.to_s.rjust(12)
60:         status = set_color status, color, true if color
61:         say "#{status}#{spaces}#{message}", nil, true
62:       end
yes?(statement, color=nil) click to toggle source

Make a question the to user and returns true if the user replies “y” or “yes”.

    # File lib/thor/shell/basic.rb, line 67
67:       def yes?(statement, color=nil)
68:         ask(statement, color) =~ is?(:yes)
69:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.