thor 0.16.0 → 1.2.1
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/CONTRIBUTING.md +15 -0
- data/README.md +23 -6
- data/bin/thor +1 -1
- data/lib/thor/actions/create_file.rb +34 -35
- data/lib/thor/actions/create_link.rb +9 -5
- data/lib/thor/actions/directory.rb +33 -23
- data/lib/thor/actions/empty_directory.rb +75 -85
- data/lib/thor/actions/file_manipulation.rb +103 -36
- data/lib/thor/actions/inject_into_file.rb +46 -36
- data/lib/thor/actions.rb +90 -68
- data/lib/thor/base.rb +302 -244
- data/lib/thor/command.rb +142 -0
- data/lib/thor/core_ext/hash_with_indifferent_access.rb +52 -24
- data/lib/thor/error.rb +90 -10
- data/lib/thor/group.rb +70 -74
- data/lib/thor/invocation.rb +63 -55
- data/lib/thor/line_editor/basic.rb +37 -0
- data/lib/thor/line_editor/readline.rb +88 -0
- data/lib/thor/line_editor.rb +17 -0
- data/lib/thor/nested_context.rb +29 -0
- data/lib/thor/parser/argument.rb +24 -28
- data/lib/thor/parser/arguments.rb +110 -102
- data/lib/thor/parser/option.rb +53 -15
- data/lib/thor/parser/options.rb +174 -97
- data/lib/thor/parser.rb +4 -4
- data/lib/thor/rake_compat.rb +12 -11
- data/lib/thor/runner.rb +159 -155
- data/lib/thor/shell/basic.rb +216 -93
- data/lib/thor/shell/color.rb +53 -40
- data/lib/thor/shell/html.rb +61 -58
- data/lib/thor/shell.rb +29 -36
- data/lib/thor/util.rb +231 -213
- data/lib/thor/version.rb +1 -1
- data/lib/thor.rb +303 -166
- data/thor.gemspec +27 -24
- metadata +36 -226
- data/.gitignore +0 -44
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/CHANGELOG.rdoc +0 -134
- data/Gemfile +0 -15
- data/Thorfile +0 -30
- data/bin/rake2thor +0 -86
- data/lib/thor/core_ext/dir_escape.rb +0 -0
- data/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/lib/thor/core_ext/ordered_hash.rb +0 -100
- data/lib/thor/task.rb +0 -132
- data/spec/actions/create_file_spec.rb +0 -170
- data/spec/actions/create_link_spec.rb +0 -81
- data/spec/actions/directory_spec.rb +0 -149
- data/spec/actions/empty_directory_spec.rb +0 -130
- data/spec/actions/file_manipulation_spec.rb +0 -370
- data/spec/actions/inject_into_file_spec.rb +0 -135
- data/spec/actions_spec.rb +0 -331
- data/spec/base_spec.rb +0 -279
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -43
- data/spec/core_ext/ordered_hash_spec.rb +0 -115
- data/spec/exit_condition_spec.rb +0 -19
- data/spec/fixtures/application.rb +0 -2
- data/spec/fixtures/app{1}/README +0 -3
- 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/COMMENTER +0 -10
- 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/doc/config.yaml.tt +0 -1
- data/spec/fixtures/enum.thor +0 -10
- 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 -190
- data/spec/fixtures/task.thor +0 -10
- data/spec/group_spec.rb +0 -216
- data/spec/invocation_spec.rb +0 -100
- data/spec/parser/argument_spec.rb +0 -53
- data/spec/parser/arguments_spec.rb +0 -66
- data/spec/parser/option_spec.rb +0 -202
- data/spec/parser/options_spec.rb +0 -330
- data/spec/rake_compat_spec.rb +0 -72
- data/spec/register_spec.rb +0 -135
- data/spec/runner_spec.rb +0 -241
- data/spec/shell/basic_spec.rb +0 -300
- data/spec/shell/color_spec.rb +0 -81
- data/spec/shell/html_spec.rb +0 -32
- data/spec/shell_spec.rb +0 -47
- data/spec/spec_helper.rb +0 -59
- data/spec/task_spec.rb +0 -80
- data/spec/thor_spec.rb +0 -418
- data/spec/util_spec.rb +0 -196
data/lib/thor/shell/html.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "basic"
|
2
2
|
|
3
3
|
class Thor
|
4
4
|
module Shell
|
@@ -10,38 +10,38 @@ class Thor
|
|
10
10
|
BOLD = "font-weight: bold"
|
11
11
|
|
12
12
|
# Set the terminal's foreground HTML color to black.
|
13
|
-
BLACK =
|
13
|
+
BLACK = "color: black"
|
14
14
|
# Set the terminal's foreground HTML color to red.
|
15
|
-
RED =
|
15
|
+
RED = "color: red"
|
16
16
|
# Set the terminal's foreground HTML color to green.
|
17
|
-
GREEN =
|
17
|
+
GREEN = "color: green"
|
18
18
|
# Set the terminal's foreground HTML color to yellow.
|
19
|
-
YELLOW =
|
19
|
+
YELLOW = "color: yellow"
|
20
20
|
# Set the terminal's foreground HTML color to blue.
|
21
|
-
BLUE =
|
21
|
+
BLUE = "color: blue"
|
22
22
|
# Set the terminal's foreground HTML color to magenta.
|
23
|
-
MAGENTA =
|
23
|
+
MAGENTA = "color: magenta"
|
24
24
|
# Set the terminal's foreground HTML color to cyan.
|
25
|
-
CYAN =
|
25
|
+
CYAN = "color: cyan"
|
26
26
|
# Set the terminal's foreground HTML color to white.
|
27
|
-
WHITE =
|
27
|
+
WHITE = "color: white"
|
28
28
|
|
29
29
|
# Set the terminal's background HTML color to black.
|
30
|
-
ON_BLACK =
|
30
|
+
ON_BLACK = "background-color: black"
|
31
31
|
# Set the terminal's background HTML color to red.
|
32
|
-
ON_RED =
|
32
|
+
ON_RED = "background-color: red"
|
33
33
|
# Set the terminal's background HTML color to green.
|
34
|
-
ON_GREEN =
|
34
|
+
ON_GREEN = "background-color: green"
|
35
35
|
# Set the terminal's background HTML color to yellow.
|
36
|
-
ON_YELLOW =
|
36
|
+
ON_YELLOW = "background-color: yellow"
|
37
37
|
# Set the terminal's background HTML color to blue.
|
38
|
-
ON_BLUE =
|
38
|
+
ON_BLUE = "background-color: blue"
|
39
39
|
# Set the terminal's background HTML color to magenta.
|
40
|
-
ON_MAGENTA =
|
40
|
+
ON_MAGENTA = "background-color: magenta"
|
41
41
|
# Set the terminal's background HTML color to cyan.
|
42
|
-
ON_CYAN =
|
42
|
+
ON_CYAN = "background-color: cyan"
|
43
43
|
# Set the terminal's background HTML color to white.
|
44
|
-
ON_WHITE =
|
44
|
+
ON_WHITE = "background-color: white"
|
45
45
|
|
46
46
|
# Set color by using a string or one of the defined constants. If a third
|
47
47
|
# option is set to true, it also adds bold to the string. This is based
|
@@ -51,13 +51,13 @@ class Thor
|
|
51
51
|
def set_color(string, *colors)
|
52
52
|
if colors.all? { |color| color.is_a?(Symbol) || color.is_a?(String) }
|
53
53
|
html_colors = colors.map { |color| lookup_color(color) }
|
54
|
-
"<span style=\"#{html_colors.join(
|
54
|
+
"<span style=\"#{html_colors.join('; ')};\">#{Thor::Util.escape_html(string)}</span>"
|
55
55
|
else
|
56
56
|
color, bold = colors
|
57
57
|
html_color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
|
58
58
|
styles = [html_color]
|
59
59
|
styles << BOLD if bold
|
60
|
-
"<span style=\"#{styles.join(
|
60
|
+
"<span style=\"#{styles.join('; ')};\">#{Thor::Util.escape_html(string)}</span>"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -67,57 +67,60 @@ class Thor
|
|
67
67
|
# ask("What is your name?")
|
68
68
|
#
|
69
69
|
# TODO: Implement #ask for Thor::Shell::HTML
|
70
|
-
def ask(statement, color=nil)
|
70
|
+
def ask(statement, color = nil)
|
71
71
|
raise NotImplementedError, "Implement #ask for Thor::Shell::HTML"
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
protected
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
def can_display_colors?
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
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")
|
83
87
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
else
|
88
|
-
super
|
88
|
+
Diff::LCS.sdiff(actual, content).each do |diff|
|
89
|
+
output_diff_line(diff)
|
89
90
|
end
|
91
|
+
else
|
92
|
+
super
|
90
93
|
end
|
94
|
+
end
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
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
|
104
107
|
end
|
108
|
+
end
|
105
109
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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?
|
112
116
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
117
|
+
@diff_lcs_loaded = begin
|
118
|
+
require "diff/lcs"
|
119
|
+
true
|
120
|
+
rescue LoadError
|
121
|
+
false
|
119
122
|
end
|
120
|
-
|
123
|
+
end
|
121
124
|
end
|
122
125
|
end
|
123
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/) && !(ENV['ANSICON']))
|
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, :error, :set_color, :yes?, :no?, :say, :say_status, :print_in_columns, :print_table, :print_wrapped, :file_collision, :terminal_width]
|
24
|
+
SHELL_DELEGATED_METHODS = [:ask, :error, :set_color, :yes?, :no?, :say, :say_error, :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, File.expand_path("shell/basic", __dir__)
|
28
|
+
autoload :Color, File.expand_path("shell/color", __dir__)
|
29
|
+
autoload :HTML, File.expand_path("shell/html", __dir__)
|
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,14 +53,9 @@ 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
|
-
module_eval <<-METHOD, __FILE__, __LINE__
|
58
|
+
module_eval <<-METHOD, __FILE__, __LINE__ + 1
|
65
59
|
def #{method}(*args,&block)
|
66
60
|
shell.#{method}(*args,&block)
|
67
61
|
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
|