thor_dleavitt 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/CHANGELOG.md +139 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +35 -0
  6. data/Thorfile +30 -0
  7. data/bin/thor_dleavitt +6 -0
  8. data/lib/thor/actions.rb +318 -0
  9. data/lib/thor/actions/create_file.rb +105 -0
  10. data/lib/thor/actions/create_link.rb +60 -0
  11. data/lib/thor/actions/directory.rb +119 -0
  12. data/lib/thor/actions/empty_directory.rb +137 -0
  13. data/lib/thor/actions/file_manipulation.rb +317 -0
  14. data/lib/thor/actions/inject_into_file.rb +109 -0
  15. data/lib/thor/base.rb +654 -0
  16. data/lib/thor/command.rb +136 -0
  17. data/lib/thor/core_ext/hash_with_indifferent_access.rb +80 -0
  18. data/lib/thor/core_ext/io_binary_read.rb +12 -0
  19. data/lib/thor/core_ext/ordered_hash.rb +100 -0
  20. data/lib/thor/error.rb +32 -0
  21. data/lib/thor/group.rb +282 -0
  22. data/lib/thor/invocation.rb +172 -0
  23. data/lib/thor/parser.rb +4 -0
  24. data/lib/thor/parser/argument.rb +74 -0
  25. data/lib/thor/parser/arguments.rb +171 -0
  26. data/lib/thor/parser/option.rb +121 -0
  27. data/lib/thor/parser/options.rb +218 -0
  28. data/lib/thor/rake_compat.rb +72 -0
  29. data/lib/thor/runner.rb +322 -0
  30. data/lib/thor/shell.rb +88 -0
  31. data/lib/thor/shell/basic.rb +422 -0
  32. data/lib/thor/shell/color.rb +148 -0
  33. data/lib/thor/shell/html.rb +127 -0
  34. data/lib/thor/util.rb +270 -0
  35. data/lib/thor/version.rb +3 -0
  36. data/lib/thor_dleavitt.rb +473 -0
  37. data/spec/actions/create_file_spec.rb +170 -0
  38. data/spec/actions/create_link_spec.rb +95 -0
  39. data/spec/actions/directory_spec.rb +169 -0
  40. data/spec/actions/empty_directory_spec.rb +129 -0
  41. data/spec/actions/file_manipulation_spec.rb +382 -0
  42. data/spec/actions/inject_into_file_spec.rb +135 -0
  43. data/spec/actions_spec.rb +331 -0
  44. data/spec/base_spec.rb +291 -0
  45. data/spec/command_spec.rb +80 -0
  46. data/spec/core_ext/hash_with_indifferent_access_spec.rb +48 -0
  47. data/spec/core_ext/ordered_hash_spec.rb +115 -0
  48. data/spec/exit_condition_spec.rb +19 -0
  49. data/spec/fixtures/application.rb +2 -0
  50. data/spec/fixtures/app{1}/README +3 -0
  51. data/spec/fixtures/bundle/execute.rb +6 -0
  52. data/spec/fixtures/bundle/main.thor +1 -0
  53. data/spec/fixtures/command.thor +10 -0
  54. data/spec/fixtures/doc/%file_name%.rb.tt +1 -0
  55. data/spec/fixtures/doc/COMMENTER +11 -0
  56. data/spec/fixtures/doc/README +3 -0
  57. data/spec/fixtures/doc/block_helper.rb +3 -0
  58. data/spec/fixtures/doc/config.rb +1 -0
  59. data/spec/fixtures/doc/config.yaml.tt +1 -0
  60. data/spec/fixtures/doc/excluding/%file_name%.rb.tt +1 -0
  61. data/spec/fixtures/enum.thor +10 -0
  62. data/spec/fixtures/group.thor +128 -0
  63. data/spec/fixtures/invoke.thor +118 -0
  64. data/spec/fixtures/path with spaces b/data/spec/fixtures/path with → spaces +0 -0
  65. data/spec/fixtures/preserve/script.sh +3 -0
  66. data/spec/fixtures/script.thor +220 -0
  67. data/spec/fixtures/subcommand.thor +17 -0
  68. data/spec/group_spec.rb +222 -0
  69. data/spec/helper.rb +67 -0
  70. data/spec/invocation_spec.rb +108 -0
  71. data/spec/parser/argument_spec.rb +53 -0
  72. data/spec/parser/arguments_spec.rb +66 -0
  73. data/spec/parser/option_spec.rb +202 -0
  74. data/spec/parser/options_spec.rb +400 -0
  75. data/spec/rake_compat_spec.rb +72 -0
  76. data/spec/register_spec.rb +197 -0
  77. data/spec/runner_spec.rb +241 -0
  78. data/spec/shell/basic_spec.rb +330 -0
  79. data/spec/shell/color_spec.rb +95 -0
  80. data/spec/shell/html_spec.rb +31 -0
  81. data/spec/shell_spec.rb +47 -0
  82. data/spec/subcommand_spec.rb +30 -0
  83. data/spec/thor_spec.rb +499 -0
  84. data/spec/util_spec.rb +196 -0
  85. data/thor.gemspec +24 -0
  86. metadata +191 -0
data/spec/util_spec.rb ADDED
@@ -0,0 +1,196 @@
1
+ require 'helper'
2
+
3
+ module Thor::Util
4
+ def self.clear_user_home!
5
+ @@user_home = nil
6
+ end
7
+ end
8
+
9
+ describe Thor::Util do
10
+ describe "#find_by_namespace" do
11
+ it "returns 'default' if no namespace is given" do
12
+ expect(Thor::Util.find_by_namespace('')).to eq(Scripts::MyDefaults)
13
+ end
14
+
15
+ it "adds 'default' if namespace starts with :" do
16
+ expect(Thor::Util.find_by_namespace(':child')).to eq(Scripts::ChildDefault)
17
+ end
18
+
19
+ it "returns nil if the namespace can't be found" do
20
+ expect(Thor::Util.find_by_namespace('thor:core_ext:ordered_hash')).to be_nil
21
+ end
22
+
23
+ it "returns a class if it matches the namespace" do
24
+ expect(Thor::Util.find_by_namespace('app:broken:counter')).to eq(BrokenCounter)
25
+ end
26
+
27
+ it "matches classes default namespace" do
28
+ expect(Thor::Util.find_by_namespace('scripts:my_script')).to eq(Scripts::MyScript)
29
+ end
30
+ end
31
+
32
+ describe "#namespace_from_thor_class" do
33
+ it "replaces constant nesting with command namespacing" do
34
+ expect(Thor::Util.namespace_from_thor_class("Foo::Bar::Baz")).to eq("foo:bar:baz")
35
+ end
36
+
37
+ it "snake-cases component strings" do
38
+ expect(Thor::Util.namespace_from_thor_class("FooBar::BarBaz::BazBoom")).to eq("foo_bar:bar_baz:baz_boom")
39
+ end
40
+
41
+ it "accepts class and module objects" do
42
+ expect(Thor::Util.namespace_from_thor_class(Thor::CoreExt::OrderedHash)).to eq("thor:core_ext:ordered_hash")
43
+ expect(Thor::Util.namespace_from_thor_class(Thor::Util)).to eq("thor:util")
44
+ end
45
+
46
+ it "removes Thor::Sandbox namespace" do
47
+ expect(Thor::Util.namespace_from_thor_class("Thor::Sandbox::Package")).to eq("package")
48
+ end
49
+ end
50
+
51
+ describe "#namespaces_in_content" do
52
+ it "returns an array of names of constants defined in the string" do
53
+ list = Thor::Util.namespaces_in_content("class Foo; class Bar < Thor; end; end; class Baz; class Bat; end; end")
54
+ expect(list).to include("foo:bar")
55
+ expect(list).not_to include("bar:bat")
56
+ end
57
+
58
+ it "doesn't put the newly-defined constants in the enclosing namespace" do
59
+ Thor::Util.namespaces_in_content("class Blat; end")
60
+ expect(defined?(Blat)).not_to be
61
+ expect(defined?(Thor::Sandbox::Blat)).to be
62
+ end
63
+ end
64
+
65
+ describe "#snake_case" do
66
+ it "preserves no-cap strings" do
67
+ expect(Thor::Util.snake_case("foo")).to eq("foo")
68
+ expect(Thor::Util.snake_case("foo_bar")).to eq("foo_bar")
69
+ end
70
+
71
+ it "downcases all-caps strings" do
72
+ expect(Thor::Util.snake_case("FOO")).to eq("foo")
73
+ expect(Thor::Util.snake_case("FOO_BAR")).to eq("foo_bar")
74
+ end
75
+
76
+ it "downcases initial-cap strings" do
77
+ expect(Thor::Util.snake_case("Foo")).to eq("foo")
78
+ end
79
+
80
+ it "replaces camel-casing with underscores" do
81
+ expect(Thor::Util.snake_case("FooBarBaz")).to eq("foo_bar_baz")
82
+ expect(Thor::Util.snake_case("Foo_BarBaz")).to eq("foo_bar_baz")
83
+ end
84
+
85
+ it "places underscores between multiple capitals" do
86
+ expect(Thor::Util.snake_case("ABClass")).to eq("a_b_class")
87
+ end
88
+ end
89
+
90
+ describe "#find_class_and_command_by_namespace" do
91
+ it "returns a Thor::Group class if full namespace matches" do
92
+ expect(Thor::Util.find_class_and_command_by_namespace("my_counter")).to eq([MyCounter, nil])
93
+ end
94
+
95
+ it "returns a Thor class if full namespace matches" do
96
+ expect(Thor::Util.find_class_and_command_by_namespace("thor")).to eq([Thor, nil])
97
+ end
98
+
99
+ it "returns a Thor class and the command name" do
100
+ expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
101
+ end
102
+
103
+ it "falls back in the namespace:command look up even if a full namespace does not match" do
104
+ Thor.const_set(:Help, Module.new)
105
+ expect(Thor::Util.find_class_and_command_by_namespace("thor:help")).to eq([Thor, "help"])
106
+ Thor.send :remove_const, :Help
107
+ end
108
+
109
+ it "falls back on the default namespace class if nothing else matches" do
110
+ expect(Thor::Util.find_class_and_command_by_namespace("test")).to eq([Scripts::MyDefaults, "test"])
111
+ end
112
+ end
113
+
114
+ describe "#thor_classes_in" do
115
+ it "returns thor classes inside the given class" do
116
+ expect(Thor::Util.thor_classes_in(MyScript)).to eq([MyScript::AnotherScript])
117
+ expect(Thor::Util.thor_classes_in(MyScript::AnotherScript)).to be_empty
118
+ end
119
+ end
120
+
121
+ describe "#user_home" do
122
+ before do
123
+ allow(ENV).to receive(:[])
124
+ Thor::Util.clear_user_home!
125
+ end
126
+
127
+ it "returns the user path if no variable is set on the environment" do
128
+ expect(Thor::Util.user_home).to eq(File.expand_path("~"))
129
+ end
130
+
131
+ it "returns the *nix system path if file cannot be expanded and separator does not exist" do
132
+ expect(File).to receive(:expand_path).with("~").and_raise(RuntimeError)
133
+ previous_value = File::ALT_SEPARATOR
134
+ capture(:stderr){ File.const_set(:ALT_SEPARATOR, false) }
135
+ expect(Thor::Util.user_home).to eq("/")
136
+ capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
137
+ end
138
+
139
+ it "returns the windows system path if file cannot be expanded and a separator exists" do
140
+ expect(File).to receive(:expand_path).with("~").and_raise(RuntimeError)
141
+ previous_value = File::ALT_SEPARATOR
142
+ capture(:stderr){ File.const_set(:ALT_SEPARATOR, true) }
143
+ expect(Thor::Util.user_home).to eq("C:/")
144
+ capture(:stderr){ File.const_set(:ALT_SEPARATOR, previous_value) }
145
+ end
146
+
147
+ it "returns HOME/.thor if set" do
148
+ allow(ENV).to receive(:[]).with("HOME").and_return("/home/user/")
149
+ expect(Thor::Util.user_home).to eq("/home/user/")
150
+ end
151
+
152
+ it "returns path with HOMEDRIVE and HOMEPATH if set" do
153
+ allow(ENV).to receive(:[]).with("HOMEDRIVE").and_return("D:/")
154
+ allow(ENV).to receive(:[]).with("HOMEPATH").and_return("Documents and Settings/James")
155
+ expect(Thor::Util.user_home).to eq("D:/Documents and Settings/James")
156
+ end
157
+
158
+ it "returns APPDATA/.thor if set" do
159
+ allow(ENV).to receive(:[]).with("APPDATA").and_return("/home/user/")
160
+ expect(Thor::Util.user_home).to eq("/home/user/")
161
+ end
162
+ end
163
+
164
+ describe "#thor_root_glob" do
165
+ before do
166
+ allow(ENV).to receive(:[])
167
+ Thor::Util.clear_user_home!
168
+ end
169
+
170
+ it "escapes globs in path" do
171
+ allow(ENV).to receive(:[]).with("HOME").and_return("/home/user{1}/")
172
+ expect(Dir).to receive(:[]).with("/home/user\\{1\\}/.thor/*").and_return([])
173
+ expect(Thor::Util.thor_root_glob).to eq([])
174
+ end
175
+ end
176
+
177
+ describe "#globs_for" do
178
+ it "escapes globs in path" do
179
+ expect(Thor::Util.globs_for("/home/apps{1}")).to eq([
180
+ "/home/apps\\{1\\}/Thorfile",
181
+ "/home/apps\\{1\\}/*.thor",
182
+ "/home/apps\\{1\\}/tasks/*.thor",
183
+ "/home/apps\\{1\\}/lib/tasks/*.thor"
184
+ ])
185
+ end
186
+ end
187
+
188
+ describe "#escape_globs" do
189
+ it "escapes ? * { } [ ] glob characters" do
190
+ expect(Thor::Util.escape_globs("apps?")).to eq("apps\\?")
191
+ expect(Thor::Util.escape_globs("apps*")).to eq("apps\\*")
192
+ expect(Thor::Util.escape_globs("apps {1}")).to eq("apps \\{1\\}")
193
+ expect(Thor::Util.escape_globs("apps [1]")).to eq("apps \\[1\\]")
194
+ end
195
+ end
196
+ end
data/thor.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+ require 'thor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.add_development_dependency 'bundler', '~> 1.0'
8
+ spec.authors = ['Yehuda Katz', 'José Valim']
9
+ spec.description = %q{Thor is a toolkit for building powerful command-line interfaces.}
10
+ spec.email = 'ruby-thor@googlegroups.com'
11
+ spec.executables = %w(thor_dleavitt)
12
+ spec.files = %w(.document CHANGELOG.md LICENSE.md README.md Thorfile thor.gemspec)
13
+ spec.files += Dir.glob("bin/**/*")
14
+ spec.files += Dir.glob("lib/**/*.rb")
15
+ spec.files += Dir.glob("spec/**/*")
16
+ spec.homepage = 'http://whatisthor.com/'
17
+ spec.licenses = ['MIT']
18
+ spec.name = 'thor_dleavitt'
19
+ spec.require_paths = ['lib']
20
+ spec.required_rubygems_version = '>= 1.3.5'
21
+ spec.summary = spec.description
22
+ spec.test_files = Dir.glob("spec/**/*")
23
+ spec.version = Thor::VERSION
24
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thor_dleavitt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.18.1
5
+ platform: ruby
6
+ authors:
7
+ - Yehuda Katz
8
+ - José Valim
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ description: Thor is a toolkit for building powerful command-line interfaces.
29
+ email: ruby-thor@googlegroups.com
30
+ executables:
31
+ - thor_dleavitt
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .document
36
+ - CHANGELOG.md
37
+ - LICENSE.md
38
+ - README.md
39
+ - Thorfile
40
+ - thor.gemspec
41
+ - bin/thor_dleavitt
42
+ - lib/thor/actions/create_file.rb
43
+ - lib/thor/actions/create_link.rb
44
+ - lib/thor/actions/directory.rb
45
+ - lib/thor/actions/empty_directory.rb
46
+ - lib/thor/actions/file_manipulation.rb
47
+ - lib/thor/actions/inject_into_file.rb
48
+ - lib/thor/actions.rb
49
+ - lib/thor/base.rb
50
+ - lib/thor/command.rb
51
+ - lib/thor/core_ext/hash_with_indifferent_access.rb
52
+ - lib/thor/core_ext/io_binary_read.rb
53
+ - lib/thor/core_ext/ordered_hash.rb
54
+ - lib/thor/error.rb
55
+ - lib/thor/group.rb
56
+ - lib/thor/invocation.rb
57
+ - lib/thor/parser/argument.rb
58
+ - lib/thor/parser/arguments.rb
59
+ - lib/thor/parser/option.rb
60
+ - lib/thor/parser/options.rb
61
+ - lib/thor/parser.rb
62
+ - lib/thor/rake_compat.rb
63
+ - lib/thor/runner.rb
64
+ - lib/thor/shell/basic.rb
65
+ - lib/thor/shell/color.rb
66
+ - lib/thor/shell/html.rb
67
+ - lib/thor/shell.rb
68
+ - lib/thor/util.rb
69
+ - lib/thor/version.rb
70
+ - lib/thor_dleavitt.rb
71
+ - spec/actions/create_file_spec.rb
72
+ - spec/actions/create_link_spec.rb
73
+ - spec/actions/directory_spec.rb
74
+ - spec/actions/empty_directory_spec.rb
75
+ - spec/actions/file_manipulation_spec.rb
76
+ - spec/actions/inject_into_file_spec.rb
77
+ - spec/actions_spec.rb
78
+ - spec/base_spec.rb
79
+ - spec/command_spec.rb
80
+ - spec/core_ext/hash_with_indifferent_access_spec.rb
81
+ - spec/core_ext/ordered_hash_spec.rb
82
+ - spec/exit_condition_spec.rb
83
+ - spec/fixtures/application.rb
84
+ - spec/fixtures/app{1}/README
85
+ - spec/fixtures/bundle/execute.rb
86
+ - spec/fixtures/bundle/main.thor
87
+ - spec/fixtures/command.thor
88
+ - spec/fixtures/doc/%file_name%.rb.tt
89
+ - spec/fixtures/doc/block_helper.rb
90
+ - spec/fixtures/doc/COMMENTER
91
+ - spec/fixtures/doc/config.rb
92
+ - spec/fixtures/doc/config.yaml.tt
93
+ - spec/fixtures/doc/excluding/%file_name%.rb.tt
94
+ - spec/fixtures/doc/README
95
+ - spec/fixtures/enum.thor
96
+ - spec/fixtures/group.thor
97
+ - spec/fixtures/invoke.thor
98
+ - spec/fixtures/path with spaces
99
+ - spec/fixtures/preserve/script.sh
100
+ - spec/fixtures/script.thor
101
+ - spec/fixtures/subcommand.thor
102
+ - spec/group_spec.rb
103
+ - spec/helper.rb
104
+ - spec/invocation_spec.rb
105
+ - spec/parser/argument_spec.rb
106
+ - spec/parser/arguments_spec.rb
107
+ - spec/parser/option_spec.rb
108
+ - spec/parser/options_spec.rb
109
+ - spec/rake_compat_spec.rb
110
+ - spec/register_spec.rb
111
+ - spec/runner_spec.rb
112
+ - spec/shell/basic_spec.rb
113
+ - spec/shell/color_spec.rb
114
+ - spec/shell/html_spec.rb
115
+ - spec/shell_spec.rb
116
+ - spec/subcommand_spec.rb
117
+ - spec/thor_spec.rb
118
+ - spec/util_spec.rb
119
+ homepage: http://whatisthor.com/
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: 1.3.5
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.0.3
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Thor is a toolkit for building powerful command-line interfaces.
143
+ test_files:
144
+ - spec/actions/create_file_spec.rb
145
+ - spec/actions/create_link_spec.rb
146
+ - spec/actions/directory_spec.rb
147
+ - spec/actions/empty_directory_spec.rb
148
+ - spec/actions/file_manipulation_spec.rb
149
+ - spec/actions/inject_into_file_spec.rb
150
+ - spec/actions_spec.rb
151
+ - spec/base_spec.rb
152
+ - spec/command_spec.rb
153
+ - spec/core_ext/hash_with_indifferent_access_spec.rb
154
+ - spec/core_ext/ordered_hash_spec.rb
155
+ - spec/exit_condition_spec.rb
156
+ - spec/fixtures/application.rb
157
+ - spec/fixtures/app{1}/README
158
+ - spec/fixtures/bundle/execute.rb
159
+ - spec/fixtures/bundle/main.thor
160
+ - spec/fixtures/command.thor
161
+ - spec/fixtures/doc/%file_name%.rb.tt
162
+ - spec/fixtures/doc/block_helper.rb
163
+ - spec/fixtures/doc/COMMENTER
164
+ - spec/fixtures/doc/config.rb
165
+ - spec/fixtures/doc/config.yaml.tt
166
+ - spec/fixtures/doc/excluding/%file_name%.rb.tt
167
+ - spec/fixtures/doc/README
168
+ - spec/fixtures/enum.thor
169
+ - spec/fixtures/group.thor
170
+ - spec/fixtures/invoke.thor
171
+ - spec/fixtures/path with spaces
172
+ - spec/fixtures/preserve/script.sh
173
+ - spec/fixtures/script.thor
174
+ - spec/fixtures/subcommand.thor
175
+ - spec/group_spec.rb
176
+ - spec/helper.rb
177
+ - spec/invocation_spec.rb
178
+ - spec/parser/argument_spec.rb
179
+ - spec/parser/arguments_spec.rb
180
+ - spec/parser/option_spec.rb
181
+ - spec/parser/options_spec.rb
182
+ - spec/rake_compat_spec.rb
183
+ - spec/register_spec.rb
184
+ - spec/runner_spec.rb
185
+ - spec/shell/basic_spec.rb
186
+ - spec/shell/color_spec.rb
187
+ - spec/shell/html_spec.rb
188
+ - spec/shell_spec.rb
189
+ - spec/subcommand_spec.rb
190
+ - spec/thor_spec.rb
191
+ - spec/util_spec.rb