thor 0.14.6 → 0.19.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +91 -31
- data/CONTRIBUTING.md +15 -0
- data/{LICENSE → LICENSE.md} +2 -2
- data/README.md +36 -296
- data/bin/thor +1 -1
- data/lib/thor/actions/create_file.rb +33 -35
- data/lib/thor/actions/create_link.rb +7 -5
- data/lib/thor/actions/directory.rb +49 -24
- data/lib/thor/actions/empty_directory.rb +68 -67
- data/lib/thor/actions/file_manipulation.rb +85 -28
- data/lib/thor/actions/inject_into_file.rb +26 -32
- data/lib/thor/actions.rb +70 -66
- data/lib/thor/base.rb +314 -237
- data/lib/thor/command.rb +133 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +34 -24
- data/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/thor/core_ext/ordered_hash.rb +94 -65
- data/lib/thor/error.rb +10 -8
- data/lib/thor/group.rb +74 -66
- data/lib/thor/invocation.rb +65 -56
- data/lib/thor/line_editor/basic.rb +35 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/parser/argument.rb +32 -29
- data/lib/thor/parser/arguments.rb +107 -93
- data/lib/thor/parser/option.rb +39 -13
- data/lib/thor/parser/options.rb +144 -97
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/rake_compat.rb +21 -16
- data/lib/thor/runner.rb +166 -153
- data/lib/thor/shell/basic.rb +268 -122
- data/lib/thor/shell/color.rb +84 -43
- data/lib/thor/shell/html.rb +71 -66
- data/lib/thor/shell.rb +30 -37
- data/lib/thor/util.rb +227 -188
- data/lib/thor/version.rb +1 -1
- data/lib/thor.rb +289 -131
- data/thor.gemspec +21 -0
- metadata +50 -189
- data/Thorfile +0 -24
- data/bin/rake2thor +0 -86
- data/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/lib/thor/task.rb +0 -114
- data/spec/actions/create_file_spec.rb +0 -170
- data/spec/actions/directory_spec.rb +0 -136
- data/spec/actions/empty_directory_spec.rb +0 -98
- data/spec/actions/file_manipulation_spec.rb +0 -310
- data/spec/actions/inject_into_file_spec.rb +0 -135
- data/spec/actions_spec.rb +0 -322
- data/spec/base_spec.rb +0 -269
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -43
- data/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/spec/fixtures/application.rb +0 -2
- data/spec/fixtures/bundle/execute.rb +0 -6
- data/spec/fixtures/bundle/main.thor +0 -1
- data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
- data/spec/fixtures/doc/README +0 -3
- data/spec/fixtures/doc/block_helper.rb +0 -3
- data/spec/fixtures/doc/components/.empty_directory +0 -0
- data/spec/fixtures/doc/config.rb +0 -1
- data/spec/fixtures/group.thor +0 -114
- data/spec/fixtures/invoke.thor +0 -112
- data/spec/fixtures/path with spaces +0 -0
- data/spec/fixtures/script.thor +0 -184
- data/spec/fixtures/task.thor +0 -10
- data/spec/group_spec.rb +0 -178
- data/spec/invocation_spec.rb +0 -100
- data/spec/parser/argument_spec.rb +0 -47
- data/spec/parser/arguments_spec.rb +0 -64
- data/spec/parser/option_spec.rb +0 -202
- data/spec/parser/options_spec.rb +0 -319
- data/spec/rake_compat_spec.rb +0 -68
- data/spec/register_spec.rb +0 -92
- data/spec/runner_spec.rb +0 -210
- data/spec/shell/basic_spec.rb +0 -223
- data/spec/shell/color_spec.rb +0 -41
- data/spec/shell/html_spec.rb +0 -27
- data/spec/shell_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -54
- data/spec/task_spec.rb +0 -69
- data/spec/thor_spec.rb +0 -334
- data/spec/util_spec.rb +0 -163
data/lib/thor/shell/html.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "thor/shell/basic"
|
|
2
2
|
|
|
3
3
|
class Thor
|
|
4
4
|
module Shell
|
|
@@ -7,56 +7,58 @@ class Thor
|
|
|
7
7
|
#
|
|
8
8
|
class HTML < Basic
|
|
9
9
|
# The start of an HTML bold sequence.
|
|
10
|
-
BOLD = "
|
|
11
|
-
# The end of an HTML bold sequence.
|
|
12
|
-
END_BOLD = "</strong>"
|
|
13
|
-
|
|
14
|
-
# Embed in a String to clear previous color selection.
|
|
15
|
-
CLEAR = "</span>"
|
|
10
|
+
BOLD = "font-weight: bold"
|
|
16
11
|
|
|
17
12
|
# Set the terminal's foreground HTML color to black.
|
|
18
|
-
BLACK =
|
|
13
|
+
BLACK = "color: black"
|
|
19
14
|
# Set the terminal's foreground HTML color to red.
|
|
20
|
-
RED =
|
|
15
|
+
RED = "color: red"
|
|
21
16
|
# Set the terminal's foreground HTML color to green.
|
|
22
|
-
GREEN =
|
|
17
|
+
GREEN = "color: green"
|
|
23
18
|
# Set the terminal's foreground HTML color to yellow.
|
|
24
|
-
YELLOW =
|
|
19
|
+
YELLOW = "color: yellow"
|
|
25
20
|
# Set the terminal's foreground HTML color to blue.
|
|
26
|
-
BLUE =
|
|
21
|
+
BLUE = "color: blue"
|
|
27
22
|
# Set the terminal's foreground HTML color to magenta.
|
|
28
|
-
MAGENTA =
|
|
23
|
+
MAGENTA = "color: magenta"
|
|
29
24
|
# Set the terminal's foreground HTML color to cyan.
|
|
30
|
-
CYAN =
|
|
25
|
+
CYAN = "color: cyan"
|
|
31
26
|
# Set the terminal's foreground HTML color to white.
|
|
32
|
-
WHITE =
|
|
27
|
+
WHITE = "color: white"
|
|
33
28
|
|
|
34
29
|
# Set the terminal's background HTML color to black.
|
|
35
|
-
ON_BLACK =
|
|
30
|
+
ON_BLACK = "background-color: black"
|
|
36
31
|
# Set the terminal's background HTML color to red.
|
|
37
|
-
ON_RED =
|
|
32
|
+
ON_RED = "background-color: red"
|
|
38
33
|
# Set the terminal's background HTML color to green.
|
|
39
|
-
ON_GREEN =
|
|
34
|
+
ON_GREEN = "background-color: green"
|
|
40
35
|
# Set the terminal's background HTML color to yellow.
|
|
41
|
-
ON_YELLOW =
|
|
36
|
+
ON_YELLOW = "background-color: yellow"
|
|
42
37
|
# Set the terminal's background HTML color to blue.
|
|
43
|
-
ON_BLUE =
|
|
38
|
+
ON_BLUE = "background-color: blue"
|
|
44
39
|
# Set the terminal's background HTML color to magenta.
|
|
45
|
-
ON_MAGENTA =
|
|
40
|
+
ON_MAGENTA = "background-color: magenta"
|
|
46
41
|
# Set the terminal's background HTML color to cyan.
|
|
47
|
-
ON_CYAN =
|
|
42
|
+
ON_CYAN = "background-color: cyan"
|
|
48
43
|
# Set the terminal's background HTML color to white.
|
|
49
|
-
ON_WHITE =
|
|
44
|
+
ON_WHITE = "background-color: white"
|
|
50
45
|
|
|
51
46
|
# Set color by using a string or one of the defined constants. If a third
|
|
52
47
|
# option is set to true, it also adds bold to the string. This is based
|
|
53
48
|
# on Highline implementation and it automatically appends CLEAR to the end
|
|
54
49
|
# of the returned String.
|
|
55
50
|
#
|
|
56
|
-
def set_color(string,
|
|
57
|
-
color
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
def set_color(string, *colors)
|
|
52
|
+
if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
|
|
53
|
+
html_colors = colors.map { |color| lookup_color(color) }
|
|
54
|
+
"<span style=\"#{html_colors.join('; ')};\">#{string}</span>"
|
|
55
|
+
else
|
|
56
|
+
color, bold = colors
|
|
57
|
+
html_color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
|
|
58
|
+
styles = [html_color]
|
|
59
|
+
styles << BOLD if bold
|
|
60
|
+
"<span style=\"#{styles.join('; ')};\">#{string}</span>"
|
|
61
|
+
end
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
# Ask something to the user and receives a response.
|
|
@@ -65,57 +67,60 @@ class Thor
|
|
|
65
67
|
# ask("What is your name?")
|
|
66
68
|
#
|
|
67
69
|
# TODO: Implement #ask for Thor::Shell::HTML
|
|
68
|
-
def ask(statement, color=nil)
|
|
70
|
+
def ask(statement, color = nil)
|
|
69
71
|
raise NotImplementedError, "Implement #ask for Thor::Shell::HTML"
|
|
70
72
|
end
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
protected
|
|
75
|
+
|
|
76
|
+
def can_display_colors?
|
|
77
|
+
true
|
|
78
|
+
end
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
# Overwrite show_diff to show diff with colors if Diff::LCS is
|
|
81
|
+
# available.
|
|
82
|
+
#
|
|
83
|
+
def show_diff(destination, content) #:nodoc:
|
|
84
|
+
if diff_lcs_loaded? && ENV["THOR_DIFF"].nil? && ENV["RAILS_DIFF"].nil?
|
|
85
|
+
actual = File.binread(destination).to_s.split("\n")
|
|
86
|
+
content = content.to_s.split("\n")
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
else
|
|
86
|
-
super
|
|
88
|
+
Diff::LCS.sdiff(actual, content).each do |diff|
|
|
89
|
+
output_diff_line(diff)
|
|
87
90
|
end
|
|
91
|
+
else
|
|
92
|
+
super
|
|
88
93
|
end
|
|
94
|
+
end
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
end
|
|
96
|
+
def output_diff_line(diff) #:nodoc:
|
|
97
|
+
case diff.action
|
|
98
|
+
when "-"
|
|
99
|
+
say "- #{diff.old_element.chomp}", :red, true
|
|
100
|
+
when "+"
|
|
101
|
+
say "+ #{diff.new_element.chomp}", :green, true
|
|
102
|
+
when "!"
|
|
103
|
+
say "- #{diff.old_element.chomp}", :red, true
|
|
104
|
+
say "+ #{diff.new_element.chomp}", :green, true
|
|
105
|
+
else
|
|
106
|
+
say " #{diff.old_element.chomp}", nil, true
|
|
102
107
|
end
|
|
108
|
+
end
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
# Check if Diff::LCS is loaded. If it is, use it to create pretty output
|
|
111
|
+
# for diff.
|
|
112
|
+
#
|
|
113
|
+
def diff_lcs_loaded? #:nodoc:
|
|
114
|
+
return true if defined?(Diff::LCS)
|
|
115
|
+
return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
|
|
110
116
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
end
|
|
117
|
+
@diff_lcs_loaded = begin
|
|
118
|
+
require "diff/lcs"
|
|
119
|
+
true
|
|
120
|
+
rescue LoadError
|
|
121
|
+
false
|
|
117
122
|
end
|
|
118
|
-
|
|
123
|
+
end
|
|
119
124
|
end
|
|
120
125
|
end
|
|
121
126
|
end
|
data/lib/thor/shell.rb
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "rbconfig"
|
|
2
2
|
|
|
3
3
|
class Thor
|
|
4
4
|
module Base
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
def self.shell
|
|
9
|
-
@shell ||= if ENV['THOR_SHELL'] && ENV['THOR_SHELL'].size > 0
|
|
10
|
-
Thor::Shell.const_get(ENV['THOR_SHELL'])
|
|
11
|
-
elsif RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
|
12
|
-
Thor::Shell::Basic
|
|
13
|
-
else
|
|
14
|
-
Thor::Shell::Color
|
|
15
|
-
end
|
|
16
|
-
end
|
|
5
|
+
class << self
|
|
6
|
+
attr_writer :shell
|
|
17
7
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
# Returns the shell used in all Thor classes. If you are in a Unix platform
|
|
9
|
+
# it will use a colored log, otherwise it will use a basic one without color.
|
|
10
|
+
#
|
|
11
|
+
def shell
|
|
12
|
+
@shell ||= if ENV["THOR_SHELL"] && !ENV["THOR_SHELL"].empty?
|
|
13
|
+
Thor::Shell.const_get(ENV["THOR_SHELL"])
|
|
14
|
+
elsif RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ && !ENV["ANSICON"]
|
|
15
|
+
Thor::Shell::Basic
|
|
16
|
+
else
|
|
17
|
+
Thor::Shell::Color
|
|
18
|
+
end
|
|
19
|
+
end
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
|
|
25
23
|
module Shell
|
|
26
|
-
SHELL_DELEGATED_METHODS = [:ask, :yes?, :no?, :say, :say_status, :print_table]
|
|
24
|
+
SHELL_DELEGATED_METHODS = [:ask, :error, :set_color, :yes?, :no?, :say, :say_status, :print_in_columns, :print_table, :print_wrapped, :file_collision, :terminal_width]
|
|
25
|
+
attr_writer :shell
|
|
27
26
|
|
|
28
|
-
autoload :Basic,
|
|
29
|
-
autoload :Color,
|
|
30
|
-
autoload :HTML,
|
|
27
|
+
autoload :Basic, "thor/shell/basic"
|
|
28
|
+
autoload :Color, "thor/shell/color"
|
|
29
|
+
autoload :HTML, "thor/shell/html"
|
|
31
30
|
|
|
32
31
|
# Add shell to initialize config values.
|
|
33
32
|
#
|
|
@@ -42,10 +41,10 @@ class Thor
|
|
|
42
41
|
#
|
|
43
42
|
# MyScript.new [1.0], { :foo => :bar }, :shell => Thor::Shell::Basic.new
|
|
44
43
|
#
|
|
45
|
-
def initialize(args=[], options={}, config={})
|
|
44
|
+
def initialize(args = [], options = {}, config = {})
|
|
46
45
|
super
|
|
47
46
|
self.shell = config[:shell]
|
|
48
|
-
|
|
47
|
+
shell.base ||= self if shell.respond_to?(:base)
|
|
49
48
|
end
|
|
50
49
|
|
|
51
50
|
# Holds the shell for the given Thor instance. If no shell is given,
|
|
@@ -54,16 +53,11 @@ class Thor
|
|
|
54
53
|
@shell ||= Thor::Base.shell.new
|
|
55
54
|
end
|
|
56
55
|
|
|
57
|
-
# Sets the shell for this thor class.
|
|
58
|
-
def shell=(shell)
|
|
59
|
-
@shell = shell
|
|
60
|
-
end
|
|
61
|
-
|
|
62
56
|
# Common methods that are delegated to the shell.
|
|
63
57
|
SHELL_DELEGATED_METHODS.each do |method|
|
|
64
58
|
module_eval <<-METHOD, __FILE__, __LINE__
|
|
65
|
-
def #{method}(*args)
|
|
66
|
-
shell.#{method}(*args)
|
|
59
|
+
def #{method}(*args,&block)
|
|
60
|
+
shell.#{method}(*args,&block)
|
|
67
61
|
end
|
|
68
62
|
METHOD
|
|
69
63
|
end
|
|
@@ -76,13 +70,12 @@ class Thor
|
|
|
76
70
|
shell.padding -= 1
|
|
77
71
|
end
|
|
78
72
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# Allow shell to be shared between invocations.
|
|
82
|
-
#
|
|
83
|
-
def _shared_configuration #:nodoc:
|
|
84
|
-
super.merge!(:shell => self.shell)
|
|
85
|
-
end
|
|
73
|
+
protected
|
|
86
74
|
|
|
75
|
+
# Allow shell to be shared between invocations.
|
|
76
|
+
#
|
|
77
|
+
def _shared_configuration #:nodoc:
|
|
78
|
+
super.merge!(:shell => shell)
|
|
79
|
+
end
|
|
87
80
|
end
|
|
88
81
|
end
|