thor 0.19.1 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +24 -0
  3. data/CONTRIBUTING.md +15 -0
  4. data/README.md +7 -1
  5. data/lib/thor.rb +31 -23
  6. data/lib/thor/actions.rb +21 -22
  7. data/lib/thor/actions/create_file.rb +1 -1
  8. data/lib/thor/actions/create_link.rb +1 -1
  9. data/lib/thor/actions/directory.rb +2 -2
  10. data/lib/thor/actions/empty_directory.rb +8 -8
  11. data/lib/thor/actions/file_manipulation.rb +23 -12
  12. data/lib/thor/actions/inject_into_file.rb +10 -14
  13. data/lib/thor/base.rb +33 -33
  14. data/lib/thor/command.rb +9 -9
  15. data/lib/thor/core_ext/hash_with_indifferent_access.rb +9 -1
  16. data/lib/thor/core_ext/io_binary_read.rb +7 -5
  17. data/lib/thor/core_ext/ordered_hash.rb +94 -63
  18. data/lib/thor/error.rb +3 -3
  19. data/lib/thor/group.rb +12 -12
  20. data/lib/thor/invocation.rb +4 -5
  21. data/lib/thor/parser/argument.rb +4 -7
  22. data/lib/thor/parser/arguments.rb +16 -16
  23. data/lib/thor/parser/option.rb +39 -19
  24. data/lib/thor/parser/options.rb +7 -5
  25. data/lib/thor/runner.rb +25 -25
  26. data/lib/thor/shell.rb +1 -1
  27. data/lib/thor/shell/basic.rb +41 -26
  28. data/lib/thor/shell/color.rb +1 -1
  29. data/lib/thor/shell/html.rb +4 -4
  30. data/lib/thor/util.rb +8 -7
  31. data/lib/thor/version.rb +1 -1
  32. data/thor.gemspec +6 -9
  33. metadata +6 -148
  34. data/Thorfile +0 -29
  35. data/spec/actions/create_file_spec.rb +0 -168
  36. data/spec/actions/create_link_spec.rb +0 -96
  37. data/spec/actions/directory_spec.rb +0 -169
  38. data/spec/actions/empty_directory_spec.rb +0 -129
  39. data/spec/actions/file_manipulation_spec.rb +0 -392
  40. data/spec/actions/inject_into_file_spec.rb +0 -135
  41. data/spec/actions_spec.rb +0 -331
  42. data/spec/base_spec.rb +0 -298
  43. data/spec/command_spec.rb +0 -79
  44. data/spec/core_ext/hash_with_indifferent_access_spec.rb +0 -48
  45. data/spec/core_ext/ordered_hash_spec.rb +0 -115
  46. data/spec/exit_condition_spec.rb +0 -19
  47. data/spec/fixtures/application.rb +0 -2
  48. data/spec/fixtures/app{1}/README +0 -3
  49. data/spec/fixtures/bundle/execute.rb +0 -6
  50. data/spec/fixtures/bundle/main.thor +0 -1
  51. data/spec/fixtures/command.thor +0 -10
  52. data/spec/fixtures/doc/%file_name%.rb.tt +0 -1
  53. data/spec/fixtures/doc/COMMENTER +0 -11
  54. data/spec/fixtures/doc/README +0 -3
  55. data/spec/fixtures/doc/block_helper.rb +0 -3
  56. data/spec/fixtures/doc/config.rb +0 -1
  57. data/spec/fixtures/doc/config.yaml.tt +0 -1
  58. data/spec/fixtures/doc/excluding/%file_name%.rb.tt +0 -1
  59. data/spec/fixtures/enum.thor +0 -10
  60. data/spec/fixtures/group.thor +0 -128
  61. data/spec/fixtures/invoke.thor +0 -131
  62. data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
  63. data/spec/fixtures/preserve/script.sh +0 -3
  64. data/spec/fixtures/script.thor +0 -220
  65. data/spec/fixtures/subcommand.thor +0 -17
  66. data/spec/group_spec.rb +0 -222
  67. data/spec/helper.rb +0 -80
  68. data/spec/invocation_spec.rb +0 -120
  69. data/spec/line_editor/basic_spec.rb +0 -28
  70. data/spec/line_editor/readline_spec.rb +0 -69
  71. data/spec/line_editor_spec.rb +0 -43
  72. data/spec/parser/argument_spec.rb +0 -53
  73. data/spec/parser/arguments_spec.rb +0 -66
  74. data/spec/parser/option_spec.rb +0 -210
  75. data/spec/parser/options_spec.rb +0 -414
  76. data/spec/quality_spec.rb +0 -75
  77. data/spec/rake_compat_spec.rb +0 -72
  78. data/spec/register_spec.rb +0 -227
  79. data/spec/runner_spec.rb +0 -246
  80. data/spec/sandbox/application.rb +0 -2
  81. data/spec/sandbox/app{1}/README +0 -3
  82. data/spec/sandbox/bundle/execute.rb +0 -6
  83. data/spec/sandbox/bundle/main.thor +0 -1
  84. data/spec/sandbox/command.thor +0 -10
  85. data/spec/sandbox/doc/%file_name%.rb.tt +0 -1
  86. data/spec/sandbox/doc/COMMENTER +0 -11
  87. data/spec/sandbox/doc/README +0 -3
  88. data/spec/sandbox/doc/block_helper.rb +0 -3
  89. data/spec/sandbox/doc/config.rb +0 -1
  90. data/spec/sandbox/doc/config.yaml.tt +0 -1
  91. data/spec/sandbox/doc/excluding/%file_name%.rb.tt +0 -1
  92. data/spec/sandbox/enum.thor +0 -10
  93. data/spec/sandbox/group.thor +0 -128
  94. data/spec/sandbox/invoke.thor +0 -131
  95. data/spec/sandbox/path with spaces b/data/spec/sandbox/path with → spaces +0 -0
  96. data/spec/sandbox/preserve/script.sh +0 -3
  97. data/spec/sandbox/script.thor +0 -220
  98. data/spec/sandbox/subcommand.thor +0 -17
  99. data/spec/shell/basic_spec.rb +0 -337
  100. data/spec/shell/color_spec.rb +0 -119
  101. data/spec/shell/html_spec.rb +0 -31
  102. data/spec/shell_spec.rb +0 -47
  103. data/spec/subcommand_spec.rb +0 -48
  104. data/spec/thor_spec.rb +0 -505
  105. data/spec/util_spec.rb +0 -196
data/Thorfile DELETED
@@ -1,29 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
-
3
- require "bundler"
4
- require "thor/rake_compat"
5
-
6
- class Default < Thor
7
- include Thor::RakeCompat
8
- Bundler::GemHelper.install_tasks
9
-
10
- desc "build", "Build thor-#{Thor::VERSION}.gem into the pkg directory"
11
- def build
12
- Rake::Task["build"].execute
13
- end
14
-
15
- desc "install", "Build and install thor-#{Thor::VERSION}.gem into system gems"
16
- def install
17
- Rake::Task["install"].execute
18
- end
19
-
20
- desc "release", "Create tag v#{Thor::VERSION} and build and push thor-#{Thor::VERSION}.gem to Rubygems"
21
- def release
22
- Rake::Task["release"].execute
23
- end
24
-
25
- desc "spec", "Run RSpec code examples"
26
- def spec
27
- exec "rspec spec"
28
- end
29
- end
@@ -1,168 +0,0 @@
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
@@ -1,96 +0,0 @@
1
- require "helper"
2
- require "thor/actions"
3
- require "tempfile"
4
-
5
- describe Thor::Actions::CreateLink do
6
- before do
7
- @silence = false
8
- @hardlink_to = File.join(Dir.tmpdir, "linkdest.rb")
9
- ::FileUtils.rm_rf(destination_root)
10
- ::FileUtils.rm_rf(@hardlink_to)
11
- end
12
-
13
- def create_link(destination = nil, config = {}, options = {})
14
- @base = MyCounter.new([1, 2], options, :destination_root => destination_root)
15
- allow(@base).to receive(:file_name).and_return("rdoc")
16
-
17
- @tempfile = Tempfile.new("config.rb")
18
-
19
- @action = Thor::Actions::CreateLink.new(@base, destination, @tempfile.path,
20
- {:verbose => !@silence}.merge(config))
21
- end
22
-
23
- def invoke!
24
- capture(:stdout) { @action.invoke! }
25
- end
26
-
27
- def revoke!
28
- capture(:stdout) { @action.revoke! }
29
- end
30
-
31
- def silence!
32
- @silence = true
33
- end
34
-
35
- describe "#invoke!" do
36
- it "creates a symbolic link for :symbolic => true" do
37
- create_link("doc/config.rb", :symbolic => true)
38
- invoke!
39
- destination_path = File.join(destination_root, "doc/config.rb")
40
- expect(File.exist?(destination_path)).to be true
41
- expect(File.symlink?(destination_path)).to be true
42
- end
43
-
44
- it "creates a hard link for :symbolic => false" do
45
- create_link(@hardlink_to, :symbolic => false)
46
- invoke!
47
- destination_path = @hardlink_to
48
- expect(File.exist?(destination_path)).to be true
49
- expect(File.symlink?(destination_path)).to be false
50
- end
51
-
52
- it "creates a symbolic link by default" do
53
- create_link("doc/config.rb")
54
- invoke!
55
- destination_path = File.join(destination_root, "doc/config.rb")
56
- expect(File.exist?(destination_path)).to be true
57
- expect(File.symlink?(destination_path)).to be true
58
- end
59
-
60
- it "does not create a link if pretending" do
61
- create_link("doc/config.rb", {}, :pretend => true)
62
- invoke!
63
- expect(File.exist?(File.join(destination_root, "doc/config.rb"))).to be false
64
- end
65
-
66
- it "shows created status to the user" do
67
- create_link("doc/config.rb")
68
- expect(invoke!).to eq(" create doc/config.rb\n")
69
- end
70
-
71
- it "does not show any information if log status is false" do
72
- silence!
73
- create_link("doc/config.rb")
74
- expect(invoke!).to be_empty
75
- end
76
- end
77
-
78
- describe "#identical?" do
79
- it "returns true if the destination link exists and is identical" do
80
- create_link("doc/config.rb")
81
- expect(@action.identical?).to be false
82
- invoke!
83
- expect(@action.identical?).to be true
84
- end
85
- end
86
-
87
- describe "#revoke!" do
88
- it "removes the symbolic link of non-existent destination" do
89
- create_link("doc/config.rb")
90
- invoke!
91
- File.delete(@tempfile.path)
92
- revoke!
93
- expect(File.symlink?(@action.destination)).to be false
94
- end
95
- end
96
- end
@@ -1,169 +0,0 @@
1
- require "helper"
2
- require "thor/actions"
3
-
4
- describe Thor::Actions::Directory do
5
- before do
6
- ::FileUtils.rm_rf(destination_root)
7
- allow(invoker).to receive(:file_name).and_return("rdoc")
8
- end
9
-
10
- def invoker
11
- @invoker ||= WhinyGenerator.new([1, 2], {}, :destination_root => destination_root)
12
- end
13
-
14
- def revoker
15
- @revoker ||= WhinyGenerator.new([1, 2], {}, :destination_root => destination_root, :behavior => :revoke)
16
- end
17
-
18
- def invoke!(*args, &block)
19
- capture(:stdout) { invoker.directory(*args, &block) }
20
- end
21
-
22
- def revoke!(*args, &block)
23
- capture(:stdout) { revoker.directory(*args, &block) }
24
- end
25
-
26
- def exists_and_identical?(source_path, destination_path)
27
- %w[config.rb README].each do |file|
28
- source = File.join(source_root, source_path, file)
29
- destination = File.join(destination_root, destination_path, file)
30
-
31
- expect(File.exist?(destination)).to be true
32
- expect(FileUtils.identical?(source, destination)).to be true
33
- end
34
- end
35
-
36
- describe "#invoke!" do
37
- it "raises an error if the source does not exist" do
38
- expect do
39
- invoke! "unknown"
40
- end.to raise_error(Thor::Error, /Could not find "unknown" in any of your source paths/)
41
- end
42
-
43
- it "does not create a directory in pretend mode" do
44
- invoke! "doc", "ghost", :pretend => true
45
- expect(File.exist?("ghost")).to be false
46
- end
47
-
48
- it "copies the whole directory recursively to the default destination" do
49
- invoke! "doc"
50
- exists_and_identical?("doc", "doc")
51
- end
52
-
53
- it "copies the whole directory recursively to the specified destination" do
54
- invoke! "doc", "docs"
55
- exists_and_identical?("doc", "docs")
56
- end
57
-
58
- it "copies only the first level files if recursive" do
59
- invoke! ".", "commands", :recursive => false
60
-
61
- file = File.join(destination_root, "commands", "group.thor")
62
- expect(File.exist?(file)).to be true
63
-
64
- file = File.join(destination_root, "commands", "doc")
65
- expect(File.exist?(file)).to be false
66
-
67
- file = File.join(destination_root, "commands", "doc", "README")
68
- expect(File.exist?(file)).to be false
69
- end
70
-
71
- it "ignores files within excluding/ directories when exclude_pattern is provided" do
72
- invoke! "doc", "docs", :exclude_pattern => /excluding\//
73
- file = File.join(destination_root, "docs", "excluding", "rdoc.rb")
74
- expect(File.exist?(file)).to be false
75
- end
76
-
77
- it "copies and evaluates files within excluding/ directory when no exclude_pattern is present" do
78
- invoke! "doc", "docs"
79
- file = File.join(destination_root, "docs", "excluding", "rdoc.rb")
80
- expect(File.exist?(file)).to be true
81
- expect(File.read(file)).to eq("BAR = BAR\n")
82
- end
83
-
84
- it "copies files from the source relative to the current path" do
85
- invoker.inside "doc" do
86
- invoke! "."
87
- end
88
- exists_and_identical?("doc", "doc")
89
- end
90
-
91
- it "copies and evaluates templates" do
92
- invoke! "doc", "docs"
93
- file = File.join(destination_root, "docs", "rdoc.rb")
94
- expect(File.exist?(file)).to be true
95
- expect(File.read(file)).to eq("FOO = FOO\n")
96
- end
97
-
98
- it "copies directories and preserves file mode" do
99
- invoke! "preserve", "preserved", :mode => :preserve
100
- original = File.join(source_root, "preserve", "script.sh")
101
- copy = File.join(destination_root, "preserved", "script.sh")
102
- expect(File.stat(original).mode).to eq(File.stat(copy).mode)
103
- end
104
-
105
- it "copies directories" do
106
- invoke! "doc", "docs"
107
- file = File.join(destination_root, "docs", "components")
108
- expect(File.exist?(file)).to be true
109
- expect(File.directory?(file)).to be true
110
- end
111
-
112
- it "does not copy .empty_directory files" do
113
- invoke! "doc", "docs"
114
- file = File.join(destination_root, "docs", "components", ".empty_directory")
115
- expect(File.exist?(file)).to be false
116
- end
117
-
118
- it "copies directories even if they are empty" do
119
- invoke! "doc/components", "docs/components"
120
- file = File.join(destination_root, "docs", "components")
121
- expect(File.exist?(file)).to be true
122
- end
123
-
124
- it "does not copy empty directories twice" do
125
- content = invoke!("doc/components", "docs/components")
126
- expect(content).not_to match(/exist/)
127
- end
128
-
129
- it "logs status" do
130
- content = invoke!("doc")
131
- expect(content).to match(/create doc\/README/)
132
- expect(content).to match(/create doc\/config\.rb/)
133
- expect(content).to match(/create doc\/rdoc\.rb/)
134
- expect(content).to match(/create doc\/components/)
135
- end
136
-
137
- it "yields a block" do
138
- checked = false
139
- invoke!("doc") do |content|
140
- checked ||= !!(content =~ /FOO/)
141
- end
142
- expect(checked).to be true
143
- end
144
-
145
- it "works with glob characters in the path" do
146
- content = invoke!("app{1}")
147
- expect(content).to match(/create app\{1\}\/README/)
148
- end
149
- end
150
-
151
- describe "#revoke!" do
152
- it "removes the destination file" do
153
- invoke! "doc"
154
- revoke! "doc"
155
-
156
- expect(File.exist?(File.join(destination_root, "doc", "README"))).to be false
157
- expect(File.exist?(File.join(destination_root, "doc", "config.rb"))).to be false
158
- expect(File.exist?(File.join(destination_root, "doc", "components"))).to be false
159
- end
160
-
161
- it "works with glob characters in the path" do
162
- invoke! "app{1}"
163
- expect(File.exist?(File.join(destination_root, "app{1}", "README"))).to be true
164
-
165
- revoke! "app{1}"
166
- expect(File.exist?(File.join(destination_root, "app{1}", "README"))).to be false
167
- end
168
- end
169
- end