thor 0.9.9 → 0.11.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/CHANGELOG.rdoc +29 -4
  2. data/README.rdoc +234 -0
  3. data/Thorfile +57 -0
  4. data/VERSION +1 -0
  5. data/bin/rake2thor +4 -0
  6. data/bin/thor +1 -1
  7. data/lib/thor.rb +216 -119
  8. data/lib/thor/actions.rb +272 -0
  9. data/lib/thor/actions/create_file.rb +102 -0
  10. data/lib/thor/actions/directory.rb +87 -0
  11. data/lib/thor/actions/empty_directory.rb +133 -0
  12. data/lib/thor/actions/file_manipulation.rb +195 -0
  13. data/lib/thor/actions/inject_into_file.rb +78 -0
  14. data/lib/thor/base.rb +510 -0
  15. data/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
  16. data/lib/thor/core_ext/ordered_hash.rb +100 -0
  17. data/lib/thor/error.rb +25 -1
  18. data/lib/thor/group.rb +263 -0
  19. data/lib/thor/invocation.rb +178 -0
  20. data/lib/thor/parser.rb +4 -0
  21. data/lib/thor/parser/argument.rb +67 -0
  22. data/lib/thor/parser/arguments.rb +145 -0
  23. data/lib/thor/parser/option.rb +132 -0
  24. data/lib/thor/parser/options.rb +142 -0
  25. data/lib/thor/rake_compat.rb +67 -0
  26. data/lib/thor/runner.rb +232 -242
  27. data/lib/thor/shell.rb +72 -0
  28. data/lib/thor/shell/basic.rb +220 -0
  29. data/lib/thor/shell/color.rb +108 -0
  30. data/lib/thor/task.rb +97 -60
  31. data/lib/thor/util.rb +230 -55
  32. data/spec/actions/create_file_spec.rb +170 -0
  33. data/spec/actions/directory_spec.rb +118 -0
  34. data/spec/actions/empty_directory_spec.rb +91 -0
  35. data/spec/actions/file_manipulation_spec.rb +242 -0
  36. data/spec/actions/inject_into_file_spec.rb +80 -0
  37. data/spec/actions_spec.rb +291 -0
  38. data/spec/base_spec.rb +236 -0
  39. data/spec/core_ext/hash_with_indifferent_access_spec.rb +43 -0
  40. data/spec/core_ext/ordered_hash_spec.rb +115 -0
  41. data/spec/fixtures/bundle/execute.rb +6 -0
  42. data/spec/fixtures/doc/config.rb +1 -0
  43. data/spec/group_spec.rb +177 -0
  44. data/spec/invocation_spec.rb +107 -0
  45. data/spec/parser/argument_spec.rb +47 -0
  46. data/spec/parser/arguments_spec.rb +64 -0
  47. data/spec/parser/option_spec.rb +212 -0
  48. data/spec/parser/options_spec.rb +255 -0
  49. data/spec/rake_compat_spec.rb +64 -0
  50. data/spec/runner_spec.rb +204 -0
  51. data/spec/shell/basic_spec.rb +206 -0
  52. data/spec/shell/color_spec.rb +41 -0
  53. data/spec/shell_spec.rb +25 -0
  54. data/spec/spec_helper.rb +52 -0
  55. data/spec/task_spec.rb +82 -0
  56. data/spec/thor_spec.rb +234 -0
  57. data/spec/util_spec.rb +196 -0
  58. metadata +69 -25
  59. data/README.markdown +0 -76
  60. data/Rakefile +0 -6
  61. data/lib/thor/options.rb +0 -242
  62. data/lib/thor/ordered_hash.rb +0 -64
  63. data/lib/thor/task_hash.rb +0 -22
  64. data/lib/thor/tasks.rb +0 -77
  65. data/lib/thor/tasks/package.rb +0 -18
@@ -1,64 +0,0 @@
1
- class Thor
2
- # This class is based on the Ruby 1.9 ordered hashes.
3
- # It keeps the semantics and most of the efficiency of normal hashes
4
- # while also keeping track of the order in which elements were set.
5
- class OrderedHash
6
- Node = Struct.new(:key, :value, :next, :prev)
7
- include Enumerable
8
-
9
- def initialize
10
- @hash = {}
11
- end
12
-
13
- def initialize_copy(other)
14
- @hash = other.instance_variable_get('@hash').clone
15
- end
16
-
17
- def [](key)
18
- @hash[key] && @hash[key].value
19
- end
20
-
21
- def []=(key, value)
22
- node = Node.new(key, value)
23
-
24
- if old = @hash[key]
25
- if old.prev
26
- old.prev.next = old.next
27
- else # old is @first and @last
28
- @first = @last = nil
29
- end
30
- end
31
-
32
- if @first.nil?
33
- @first = @last = node
34
- else
35
- node.prev = @last
36
- @last.next = node
37
- @last = node
38
- end
39
-
40
- @hash[key] = node
41
- value
42
- end
43
-
44
- def each
45
- return unless @first
46
- yield [@first.key, @first.value]
47
- node = @first
48
- yield [node.key, node.value] while node = node.next
49
- self
50
- end
51
-
52
- def values
53
- self.map { |k, v| v }
54
- end
55
-
56
- def +(other)
57
- new = clone
58
- other.each do |key, value|
59
- new[key] = value unless self[key]
60
- end
61
- new
62
- end
63
- end
64
- end
@@ -1,22 +0,0 @@
1
- require 'thor/ordered_hash'
2
- require 'thor/task'
3
-
4
- class Thor::TaskHash < Thor::OrderedHash
5
- def initialize(klass)
6
- super()
7
- @klass = klass
8
- end
9
-
10
- def each(local = false, &block)
11
- super() { |k, t| yield k, t.with_klass(@klass) }
12
- @klass.superclass.tasks.each { |k, t| yield k, t.with_klass(@klass) } unless local || @klass == Thor
13
- end
14
-
15
- def [](name)
16
- if task = super(name) || (@klass == Thor && @klass.superclass.tasks[name])
17
- return task.with_klass(@klass)
18
- end
19
-
20
- Thor::Task.dynamic(name, @klass)
21
- end
22
- end
data/lib/thor/tasks.rb DELETED
@@ -1,77 +0,0 @@
1
- require "thor"
2
- require "fileutils"
3
-
4
- class Thor
5
- def self.package_task(spec)
6
- desc "package", "package up the gem"
7
- define_method :package do
8
- FileUtils.mkdir_p(File.join(Dir.pwd, "pkg"))
9
- Gem::Builder.new(spec).build
10
- FileUtils.mv(spec.file_name, File.join(Dir.pwd, "pkg", spec.file_name))
11
- end
12
- end
13
-
14
- def self.install_task(spec)
15
- package_task spec
16
-
17
- null, sudo, gem = RUBY_PLATFORM =~ /w(in)?32$/ ? ['NUL', '', 'gem.bat'] :
18
- ['/dev/null', 'sudo', 'gem']
19
-
20
- desc "install", "install the gem"
21
- define_method :install do
22
- old_stderr, $stderr = $stderr.dup, File.open(null, "w")
23
- package
24
- $stderr = old_stderr
25
- system %{#{sudo} #{Gem.ruby} -S #{gem} install pkg/#{spec.name}-#{spec.version} --no-rdoc --no-ri --no-update-sources}
26
- end
27
- end
28
-
29
- def self.spec_task(file_list, opts = {})
30
- name = opts.delete(:name) || "spec"
31
- rcov_dir = opts.delete(:rcov_dir) || "coverage"
32
- file_list = file_list.map {|f| %["#{f}"]}.join(" ")
33
- verbose = opts.delete(:verbose)
34
- opts = {:format => "specdoc", :color => true}.merge(opts)
35
-
36
- rcov_opts = convert_task_options(opts.delete(:rcov) || {})
37
- rcov = !rcov_opts.empty?
38
- options = convert_task_options(opts)
39
-
40
- if rcov
41
- FileUtils.rm_rf(File.join(Dir.pwd, rcov_dir))
42
- end
43
-
44
- desc(name, "spec task")
45
- define_method(name) do
46
- cmd = "ruby "
47
- if rcov
48
- cmd << "-S rcov -o #{rcov_dir} #{rcov_opts} "
49
- end
50
- cmd << `which spec`.chomp
51
- cmd << " -- " if rcov
52
- cmd << " "
53
- cmd << file_list
54
- cmd << " "
55
- cmd << options
56
- puts cmd if verbose
57
- system(cmd)
58
- exit($?.exitstatus)
59
- end
60
- end
61
-
62
- private
63
- def self.convert_task_options(opts)
64
- opts.map do |key, value|
65
- case value
66
- when true
67
- "--#{key}"
68
- when Array
69
- value.map {|v| "--#{key} #{v.inspect}"}.join(" ")
70
- when nil, false
71
- ""
72
- else
73
- "--#{key} #{value.inspect}"
74
- end
75
- end.join(" ")
76
- end
77
- end
@@ -1,18 +0,0 @@
1
- require "thor/task"
2
-
3
- class Thor::PackageTask < Thor::Task
4
- attr_accessor :spec
5
- attr_accessor :opts
6
-
7
- def initialize(gemspec, opts = {})
8
- super(:package, "build a gem package")
9
- @spec = gemspec
10
- @opts = {:dir => File.join(Dir.pwd, "pkg")}.merge(opts)
11
- end
12
-
13
- def run
14
- FileUtils.mkdir_p(@opts[:dir])
15
- Gem::Builder.new(spec).build
16
- FileUtils.mv(spec.file_name, File.join(@opts[:dir], spec.file_name))
17
- end
18
- end