groovenauts-thor 0.19.1 → 0.19.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -24
- data/groovenauts-thor.gemspec +1 -1
- data/lib/thor/base.rb +1 -1
- data/lib/thor/core_ext/ordered_hash.rb +63 -94
- data/lib/thor/parser/arguments.rb +1 -1
- data/lib/thor/parser/option.rb +0 -15
- data/lib/thor/version.rb +1 -1
- data/spec/actions/create_file_spec.rb +168 -0
- data/spec/actions/create_link_spec.rb +96 -0
- data/spec/actions/directory_spec.rb +169 -0
- data/spec/actions/empty_directory_spec.rb +129 -0
- data/spec/actions/file_manipulation_spec.rb +392 -0
- data/spec/actions/inject_into_file_spec.rb +135 -0
- data/spec/actions_spec.rb +331 -0
- data/spec/base_spec.rb +298 -0
- data/spec/command_spec.rb +79 -0
- data/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
- data/spec/core_ext/ordered_hash_spec.rb +115 -0
- data/spec/exit_condition_spec.rb +19 -0
- data/spec/fixtures/application.rb +2 -0
- data/spec/fixtures/app{1}/README +3 -0
- data/spec/fixtures/bundle/execute.rb +6 -0
- data/spec/fixtures/bundle/main.thor +1 -0
- data/spec/fixtures/command.thor +10 -0
- data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
- data/spec/fixtures/doc/COMMENTER +11 -0
- data/spec/fixtures/doc/README +3 -0
- data/spec/fixtures/doc/block_helper.rb +3 -0
- data/spec/fixtures/doc/config.rb +1 -0
- data/spec/fixtures/doc/config.yaml.tt +1 -0
- data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/fixtures/enum.thor +10 -0
- data/spec/fixtures/group.thor +128 -0
- data/spec/fixtures/invoke.thor +131 -0
- data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
- data/spec/fixtures/preserve/script.sh +3 -0
- data/spec/fixtures/script.thor +220 -0
- data/spec/fixtures/subcommand.thor +17 -0
- data/spec/group_spec.rb +222 -0
- data/spec/helper.rb +80 -0
- data/spec/invocation_spec.rb +120 -0
- data/spec/line_editor/basic_spec.rb +28 -0
- data/spec/line_editor/readline_spec.rb +69 -0
- data/spec/line_editor_spec.rb +43 -0
- data/spec/parser/argument_spec.rb +53 -0
- data/spec/parser/arguments_spec.rb +66 -0
- data/spec/parser/option_spec.rb +210 -0
- data/spec/parser/options_spec.rb +414 -0
- data/spec/quality_spec.rb +75 -0
- data/spec/rake_compat_spec.rb +72 -0
- data/spec/register_spec.rb +227 -0
- data/spec/runner_spec.rb +246 -0
- data/spec/sandbox/application.rb +2 -0
- data/spec/sandbox/app{1}/README +3 -0
- data/spec/sandbox/bundle/execute.rb +6 -0
- data/spec/sandbox/bundle/main.thor +1 -0
- data/spec/sandbox/command.thor +10 -0
- data/spec/sandbox/doc/%file_name%.rb.tt +1 -0
- data/spec/sandbox/doc/COMMENTER +11 -0
- data/spec/sandbox/doc/README +3 -0
- data/spec/sandbox/doc/block_helper.rb +3 -0
- data/spec/sandbox/doc/config.rb +1 -0
- data/spec/sandbox/doc/config.yaml.tt +1 -0
- data/spec/sandbox/doc/excluding/%file_name%.rb.tt +1 -0
- data/spec/sandbox/enum.thor +10 -0
- data/spec/sandbox/group.thor +128 -0
- data/spec/sandbox/invoke.thor +131 -0
- data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
- data/spec/sandbox/preserve/script.sh +3 -0
- data/spec/sandbox/script.thor +220 -0
- data/spec/sandbox/subcommand.thor +17 -0
- data/spec/shell/basic_spec.rb +337 -0
- data/spec/shell/color_spec.rb +119 -0
- data/spec/shell/html_spec.rb +31 -0
- data/spec/shell_spec.rb +47 -0
- data/spec/subcommand_spec.rb +71 -0
- data/spec/thor_spec.rb +505 -0
- data/spec/util_spec.rb +196 -0
- metadata +146 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 951deb43fb72171180a7b1c8252e4d828e53739d
|
4
|
+
data.tar.gz: d241708a49b81fc3ce9e6e9c5507b21945c5144e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56285e5f1f3d967d1af3d1044a7aa2f08c6e918416dfd97fab455e3c94d71a7ab8280bea36dec1a3391719f7aeee3ac568303b5fdeb830e08053f56652a02438
|
7
|
+
data.tar.gz: c0a5863d78e69670fe0612ade541c3cf2b68dae3e2a88acca5c29bb1d0f642a667d09e24506cf9eb7d4d1843b07579a39338860eed6fa2ea529480a9a84a5a7c
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,3 @@
|
|
1
|
-
## 0.19.1, release 2014-03-24
|
2
|
-
* Fix `say` non-String break regression
|
3
|
-
|
4
|
-
## 0.19.0, release 2014-03-22
|
5
|
-
* Add support for a default to #ask
|
6
|
-
* Avoid @namespace not initialized warning
|
7
|
-
* Avoid private attribute? warning
|
8
|
-
* Fix initializing with unknown options
|
9
|
-
* Loosen required_rubygems_version for compatibility with Ubuntu 10.04
|
10
|
-
* Shell#ask: support a noecho option for stdin
|
11
|
-
* Shell#ask: change API to be :echo => false
|
12
|
-
* Display a message without a stack trace for ambiguous commands
|
13
|
-
* Make say and say_status thread safe
|
14
|
-
* Dependency for console io version check
|
15
|
-
* Alias --help to help on subcommands
|
16
|
-
* Use mime-types 1.x for Ruby 1.8.7 compatibility for Ruby 1.8 only
|
17
|
-
* Accept .tt files as templates
|
18
|
-
* Check if numeric value is in enum
|
19
|
-
* Use Readline for user input
|
20
|
-
* Fix dispatching of subcommands (concerning :help and *args)
|
21
|
-
* Fix warnings when running specs with `$VERBOSE = true`
|
22
|
-
* Make subcommand help more consistent
|
23
|
-
* Make the current command chain accessible in command
|
24
|
-
|
25
1
|
## 0.18.1, release 2013-03-30
|
26
2
|
* Revert regressions found in 0.18.0
|
27
3
|
|
data/groovenauts-thor.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = "Thor is a toolkit for building powerful command-line interfaces."
|
11
11
|
# spec.email = "ruby-thor@googlegroups.com"
|
12
12
|
spec.email = "t-akima@groovenauts.jp"
|
13
|
-
# spec.executables = %w[thor]
|
14
13
|
spec.executables = %w[groovenauts-thor]
|
15
14
|
spec.files = %w[.document groovenauts-thor.gemspec] + Dir['*.md', 'bin/*', 'lib/**/*.rb']
|
16
15
|
# spec.homepage = "http://whatisthor.com/"
|
@@ -20,5 +19,6 @@ Gem::Specification.new do |spec|
|
|
20
19
|
spec.require_paths = %w[lib]
|
21
20
|
spec.required_rubygems_version = ">= 1.3.5"
|
22
21
|
spec.summary = spec.description
|
22
|
+
spec.test_files = Dir.glob("spec/**/*")
|
23
23
|
spec.version = Thor::VERSION
|
24
24
|
end
|
data/lib/thor/base.rb
CHANGED
@@ -1,127 +1,96 @@
|
|
1
1
|
class Thor
|
2
|
-
module CoreExt
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
module CoreExt #:nodoc:
|
3
|
+
if RUBY_VERSION >= "1.9"
|
4
|
+
class OrderedHash < ::Hash
|
5
|
+
end
|
6
|
+
else
|
7
|
+
# This class is based on the Ruby 1.9 ordered hashes.
|
8
|
+
#
|
9
|
+
# It keeps the semantics and most of the efficiency of normal hashes
|
10
|
+
# while also keeping track of the order in which elements were set.
|
11
|
+
#
|
12
|
+
class OrderedHash #:nodoc:
|
13
|
+
include Enumerable
|
14
|
+
|
15
|
+
Node = Struct.new(:key, :value, :next, :prev)
|
9
16
|
|
10
|
-
def
|
11
|
-
|
12
|
-
# make a deep copy of keys
|
13
|
-
@keys = other.keys
|
17
|
+
def initialize
|
18
|
+
@hash = {}
|
14
19
|
end
|
15
20
|
|
16
|
-
def []
|
17
|
-
@
|
18
|
-
super
|
21
|
+
def [](key)
|
22
|
+
@hash[key] && @hash[key].value
|
19
23
|
end
|
20
24
|
|
21
|
-
def
|
22
|
-
if key
|
23
|
-
|
24
|
-
|
25
|
+
def []=(key, value)
|
26
|
+
if node = @hash[key] # rubocop:disable AssignmentInCondition
|
27
|
+
node.value = value
|
28
|
+
else
|
29
|
+
node = Node.new(key, value)
|
30
|
+
|
31
|
+
if !defined?(@first) || @first.nil?
|
32
|
+
@first = @last = node
|
33
|
+
else
|
34
|
+
node.prev = @last
|
35
|
+
@last.next = node
|
36
|
+
@last = node
|
37
|
+
end
|
25
38
|
end
|
26
|
-
super
|
27
|
-
end
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
sync_keys!
|
32
|
-
self
|
40
|
+
@hash[key] = node
|
41
|
+
value
|
33
42
|
end
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
44
|
+
def delete(key)
|
45
|
+
if node = @hash[key] # rubocop:disable AssignmentInCondition
|
46
|
+
prev_node = node.prev
|
47
|
+
next_node = node.next
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
49
|
+
next_node.prev = prev_node if next_node
|
50
|
+
prev_node.next = next_node if prev_node
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
52
|
+
@first = next_node if @first == node
|
53
|
+
@last = prev_node if @last == node
|
48
54
|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
55
|
+
value = node.value
|
56
|
+
end
|
52
57
|
|
53
|
-
|
54
|
-
|
58
|
+
@hash.delete(key)
|
59
|
+
value
|
55
60
|
end
|
56
61
|
|
57
|
-
def
|
58
|
-
|
59
|
-
@keys.each { |key| yield(key) }
|
60
|
-
self
|
62
|
+
def keys
|
63
|
+
map { |k, v| k }
|
61
64
|
end
|
62
65
|
|
63
|
-
def
|
64
|
-
|
65
|
-
@keys.each { |key| yield(self[key]) }
|
66
|
-
self
|
66
|
+
def values
|
67
|
+
map { |k, v| v }
|
67
68
|
end
|
68
69
|
|
69
70
|
def each
|
70
|
-
return
|
71
|
-
@
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def each_pair
|
76
|
-
return to_enum(:each_pair) unless block_given?
|
77
|
-
@keys.each { |key| yield(key, self[key]) }
|
71
|
+
return unless defined?(@first) && @first
|
72
|
+
yield [@first.key, @first.value]
|
73
|
+
node = @first
|
74
|
+
yield [node.key, node.value] while node = node.next # rubocop:disable AssignmentInCondition
|
78
75
|
self
|
79
76
|
end
|
80
77
|
|
81
|
-
|
82
|
-
|
83
|
-
def clear
|
84
|
-
super
|
85
|
-
@keys.clear
|
86
|
-
self
|
87
|
-
end
|
88
|
-
|
89
|
-
def shift
|
90
|
-
k = @keys.first
|
91
|
-
v = delete(k)
|
92
|
-
[k, v]
|
93
|
-
end
|
78
|
+
def merge(other)
|
79
|
+
hash = self.class.new
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
|
98
|
-
else
|
99
|
-
other_hash.each { |k, v| self[k] = v }
|
81
|
+
each do |key, value|
|
82
|
+
hash[key] = value
|
100
83
|
end
|
101
|
-
self
|
102
|
-
end
|
103
|
-
|
104
|
-
alias_method :update, :merge!
|
105
|
-
|
106
|
-
def merge(other_hash, &block)
|
107
|
-
dup.merge!(other_hash, &block)
|
108
|
-
end
|
109
84
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
@keys = other.keys
|
114
|
-
self
|
115
|
-
end
|
85
|
+
other.each do |key, value|
|
86
|
+
hash[key] = value
|
87
|
+
end
|
116
88
|
|
117
|
-
|
118
|
-
"#<#{self.class} #{super}>"
|
89
|
+
hash
|
119
90
|
end
|
120
91
|
|
121
|
-
|
122
|
-
|
123
|
-
def sync_keys!
|
124
|
-
@keys.delete_if { |k| !key?(k) }
|
92
|
+
def empty?
|
93
|
+
@hash.empty?
|
125
94
|
end
|
126
95
|
end
|
127
96
|
end
|
data/lib/thor/parser/option.rb
CHANGED
@@ -108,21 +108,6 @@ class Thor
|
|
108
108
|
|
109
109
|
def validate!
|
110
110
|
fail ArgumentError, "An option cannot be boolean and required." if boolean? && required?
|
111
|
-
validate_default_type!
|
112
|
-
end
|
113
|
-
|
114
|
-
def validate_default_type!
|
115
|
-
default_type = case @default
|
116
|
-
when nil
|
117
|
-
return
|
118
|
-
when TrueClass, FalseClass
|
119
|
-
:boolean
|
120
|
-
when Numeric
|
121
|
-
:numeric
|
122
|
-
when Hash, Array, String
|
123
|
-
@default.class.name.downcase.to_sym
|
124
|
-
end
|
125
|
-
fail ArgumentError, "An option's default must match its type." unless default_type == @type
|
126
111
|
end
|
127
112
|
|
128
113
|
def dasherized?
|
data/lib/thor/version.rb
CHANGED
@@ -0,0 +1,168 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "thor/actions"
|
3
|
+
|
4
|
+
describe Thor::Actions::CreateFile do
|
5
|
+
before do
|
6
|
+
@silence = false
|
7
|
+
::FileUtils.rm_rf(destination_root)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_file(destination = nil, config = {}, options = {})
|
11
|
+
@base = MyCounter.new([1, 2], options, :destination_root => destination_root)
|
12
|
+
allow(@base).to receive(:file_name).and_return("rdoc")
|
13
|
+
|
14
|
+
@action = Thor::Actions::CreateFile.new(@base, destination, "CONFIGURATION", {:verbose => !@silence}.merge(config))
|
15
|
+
end
|
16
|
+
|
17
|
+
def invoke!
|
18
|
+
capture(:stdout) { @action.invoke! }
|
19
|
+
end
|
20
|
+
|
21
|
+
def revoke!
|
22
|
+
capture(:stdout) { @action.revoke! }
|
23
|
+
end
|
24
|
+
|
25
|
+
def silence!
|
26
|
+
@silence = true
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#invoke!" do
|
30
|
+
it "creates a file" do
|
31
|
+
create_file("doc/config.rb")
|
32
|
+
invoke!
|
33
|
+
expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not create a file if pretending" do
|
37
|
+
create_file("doc/config.rb", {}, :pretend => true)
|
38
|
+
invoke!
|
39
|
+
expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "shows created status to the user" do
|
43
|
+
create_file("doc/config.rb")
|
44
|
+
expect(invoke!).to eq(" create doc/config.rb\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not show any information if log status is false" do
|
48
|
+
silence!
|
49
|
+
create_file("doc/config.rb")
|
50
|
+
expect(invoke!).to be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns the given destination" do
|
54
|
+
capture(:stdout) do
|
55
|
+
expect(create_file("doc/config.rb").invoke!).to eq("doc/config.rb")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "converts encoded instructions" do
|
60
|
+
create_file("doc/%file_name%.rb.tt")
|
61
|
+
invoke!
|
62
|
+
expect(File.exist?(File.join(destination_root, "doc/rdoc.rb.tt"))).to be true
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "when file exists" do
|
66
|
+
before do
|
67
|
+
create_file("doc/config.rb")
|
68
|
+
invoke!
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "and is identical" do
|
72
|
+
it "shows identical status" do
|
73
|
+
create_file("doc/config.rb")
|
74
|
+
invoke!
|
75
|
+
expect(invoke!).to eq(" identical doc/config.rb\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "and is not identical" do
|
80
|
+
before do
|
81
|
+
File.open(File.join(destination_root, "doc/config.rb"), "w") { |f| f.write("FOO = 3") }
|
82
|
+
end
|
83
|
+
|
84
|
+
it "shows forced status to the user if force is given" do
|
85
|
+
expect(create_file("doc/config.rb", {}, :force => true)).not_to be_identical
|
86
|
+
expect(invoke!).to eq(" force doc/config.rb\n")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "shows skipped status to the user if skip is given" do
|
90
|
+
expect(create_file("doc/config.rb", {}, :skip => true)).not_to be_identical
|
91
|
+
expect(invoke!).to eq(" skip doc/config.rb\n")
|
92
|
+
end
|
93
|
+
|
94
|
+
it "shows forced status to the user if force is configured" do
|
95
|
+
expect(create_file("doc/config.rb", :force => true)).not_to be_identical
|
96
|
+
expect(invoke!).to eq(" force doc/config.rb\n")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "shows skipped status to the user if skip is configured" do
|
100
|
+
expect(create_file("doc/config.rb", :skip => true)).not_to be_identical
|
101
|
+
expect(invoke!).to eq(" skip doc/config.rb\n")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "shows conflict status to the user" do
|
105
|
+
file = File.join(destination_root, "doc/config.rb")
|
106
|
+
expect(create_file("doc/config.rb")).not_to be_identical
|
107
|
+
expect(Thor::LineEditor).to receive(:readline).with("Overwrite #{file}? (enter \"h\" for help) [Ynaqdh] ", anything).and_return("s")
|
108
|
+
|
109
|
+
content = invoke!
|
110
|
+
expect(content).to match(/conflict doc\/config\.rb/)
|
111
|
+
expect(content).to match(/skip doc\/config\.rb/)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "creates the file if the file collision menu returns true" do
|
115
|
+
create_file("doc/config.rb")
|
116
|
+
expect(Thor::LineEditor).to receive(:readline).and_return("y")
|
117
|
+
expect(invoke!).to match(/force doc\/config\.rb/)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "skips the file if the file collision menu returns false" do
|
121
|
+
create_file("doc/config.rb")
|
122
|
+
expect(Thor::LineEditor).to receive(:readline).and_return("n")
|
123
|
+
expect(invoke!).to match(/skip doc\/config\.rb/)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "executes the block given to show file content" do
|
127
|
+
create_file("doc/config.rb")
|
128
|
+
expect(Thor::LineEditor).to receive(:readline).and_return("d", "n")
|
129
|
+
expect(@base.shell).to receive(:system).with(/diff -u/)
|
130
|
+
invoke!
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#revoke!" do
|
137
|
+
it "removes the destination file" do
|
138
|
+
create_file("doc/config.rb")
|
139
|
+
invoke!
|
140
|
+
revoke!
|
141
|
+
expect(File.exist?(@action.destination)).to be false
|
142
|
+
end
|
143
|
+
|
144
|
+
it "does not raise an error if the file does not exist" do
|
145
|
+
create_file("doc/config.rb")
|
146
|
+
revoke!
|
147
|
+
expect(File.exist?(@action.destination)).to be false
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "#exists?" do
|
152
|
+
it "returns true if the destination file exists" do
|
153
|
+
create_file("doc/config.rb")
|
154
|
+
expect(@action.exists?).to be false
|
155
|
+
invoke!
|
156
|
+
expect(@action.exists?).to be true
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#identical?" do
|
161
|
+
it "returns true if the destination file exists and is identical" do
|
162
|
+
create_file("doc/config.rb")
|
163
|
+
expect(@action.identical?).to be false
|
164
|
+
invoke!
|
165
|
+
expect(@action.identical?).to be true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|