colorcode_convert_rgb 0.1.0

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.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +23 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +40 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/colorcode_convert_rgb.gemspec +30 -0
  10. data/exe/colorcode_convert_rgb +4 -0
  11. data/lib/colorcode_convert_rgb.rb +7 -0
  12. data/lib/colorcode_convert_rgb/cli.rb +13 -0
  13. data/lib/colorcode_convert_rgb/version.rb +3 -0
  14. data/vendor/bundle/ruby/2.5.0/bin/colorcode_convert_rgb +27 -0
  15. data/vendor/bundle/ruby/2.5.0/bin/rake +27 -0
  16. data/vendor/bundle/ruby/2.5.0/bin/thor +27 -0
  17. data/vendor/bundle/ruby/2.5.0/cache/minitest-5.14.2.gem +0 -0
  18. data/vendor/bundle/ruby/2.5.0/cache/rake-12.3.3.gem +0 -0
  19. data/vendor/bundle/ruby/2.5.0/cache/thor-1.0.1.gem +0 -0
  20. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/.autotest +34 -0
  21. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/History.rdoc +1397 -0
  22. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Manifest.txt +27 -0
  23. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/README.rdoc +764 -0
  24. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Rakefile +74 -0
  25. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/design_rationale.rb +52 -0
  26. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/hoe/minitest.rb +32 -0
  27. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest.rb +1056 -0
  28. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/assertions.rb +807 -0
  29. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/autorun.rb +13 -0
  30. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/benchmark.rb +455 -0
  31. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/expectations.rb +303 -0
  32. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/hell.rb +11 -0
  33. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/mock.rb +240 -0
  34. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/parallel.rb +70 -0
  35. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride.rb +4 -0
  36. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride_plugin.rb +142 -0
  37. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/spec.rb +342 -0
  38. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/test.rb +220 -0
  39. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/unit.rb +45 -0
  40. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/metametameta.rb +136 -0
  41. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_assertions.rb +1575 -0
  42. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_benchmark.rb +137 -0
  43. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_mock.rb +872 -0
  44. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_reporter.rb +299 -0
  45. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_spec.rb +1061 -0
  46. data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_test.rb +1084 -0
  47. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/CONTRIBUTING.rdoc +43 -0
  48. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Gemfile +3 -0
  49. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/History.rdoc +2344 -0
  50. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/MIT-LICENSE +21 -0
  51. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/README.rdoc +156 -0
  52. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Rakefile +41 -0
  53. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/azure-pipelines.yml +11 -0
  54. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/bundle +105 -0
  55. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/console +7 -0
  56. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rake +29 -0
  57. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rdoc +29 -0
  58. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rubocop +29 -0
  59. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/setup +6 -0
  60. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/command_line_usage.rdoc +158 -0
  61. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile1 +38 -0
  62. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile2 +35 -0
  63. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/a.c +6 -0
  64. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/b.c +6 -0
  65. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/main.c +11 -0
  66. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/glossary.rdoc +42 -0
  67. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/jamis.rb +592 -0
  68. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/proto_rake.rdoc +127 -0
  69. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rake.1 +156 -0
  70. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rakefile.rdoc +622 -0
  71. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rational.rdoc +151 -0
  72. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake +27 -0
  73. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake.rb +71 -0
  74. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb +824 -0
  75. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/backtrace.rb +24 -0
  76. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/clean.rb +78 -0
  77. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cloneable.rb +17 -0
  78. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cpu_counter.rb +107 -0
  79. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/default_loader.rb +15 -0
  80. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/dsl_definition.rb +195 -0
  81. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/early_time.rb +22 -0
  82. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/core.rb +26 -0
  83. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/string.rb +176 -0
  84. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_creation_task.rb +25 -0
  85. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_list.rb +435 -0
  86. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_task.rb +54 -0
  87. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils.rb +137 -0
  88. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils_ext.rb +145 -0
  89. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_chain.rb +57 -0
  90. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_exception_mixin.rb +17 -0
  91. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/late_time.rb +18 -0
  92. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/linked_list.rb +112 -0
  93. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/loaders/makefile.rb +54 -0
  94. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/multi_task.rb +14 -0
  95. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/name_space.rb +38 -0
  96. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/packagetask.rb +207 -0
  97. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/phony.rb +16 -0
  98. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/private_reader.rb +21 -0
  99. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/promise.rb +100 -0
  100. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/pseudo_status.rb +30 -0
  101. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb +67 -0
  102. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_test_loader.rb +27 -0
  103. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rule_recursion_overflow_error.rb +20 -0
  104. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/scope.rb +43 -0
  105. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task.rb +413 -0
  106. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_argument_error.rb +8 -0
  107. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_arguments.rb +109 -0
  108. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_manager.rb +324 -0
  109. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/tasklib.rb +12 -0
  110. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/testtask.rb +224 -0
  111. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_history_display.rb +49 -0
  112. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_pool.rb +163 -0
  113. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/trace_output.rb +23 -0
  114. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/version.rb +10 -0
  115. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/win32.rb +51 -0
  116. data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/rake.gemspec +42 -0
  117. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/.document +5 -0
  118. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CHANGELOG.md +220 -0
  119. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CONTRIBUTING.md +15 -0
  120. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/LICENSE.md +20 -0
  121. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/README.md +51 -0
  122. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/bin/thor +6 -0
  123. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor.rb +517 -0
  124. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions.rb +336 -0
  125. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_file.rb +104 -0
  126. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_link.rb +61 -0
  127. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/directory.rb +108 -0
  128. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/empty_directory.rb +143 -0
  129. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb +373 -0
  130. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/inject_into_file.rb +120 -0
  131. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb +699 -0
  132. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb +142 -0
  133. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
  134. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/error.rb +110 -0
  135. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb +281 -0
  136. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb +178 -0
  137. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor.rb +17 -0
  138. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/basic.rb +37 -0
  139. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/readline.rb +88 -0
  140. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/nested_context.rb +29 -0
  141. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser.rb +4 -0
  142. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/argument.rb +70 -0
  143. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/arguments.rb +175 -0
  144. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/option.rb +159 -0
  145. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/options.rb +236 -0
  146. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/rake_compat.rb +72 -0
  147. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/runner.rb +325 -0
  148. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell.rb +81 -0
  149. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/basic.rb +491 -0
  150. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/color.rb +153 -0
  151. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/html.rb +126 -0
  152. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/util.rb +284 -0
  153. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/version.rb +3 -0
  154. data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/thor.gemspec +28 -0
  155. data/vendor/bundle/ruby/2.5.0/specifications/minitest-5.14.2.gemspec +38 -0
  156. data/vendor/bundle/ruby/2.5.0/specifications/rake-12.3.3.gemspec +43 -0
  157. data/vendor/bundle/ruby/2.5.0/specifications/thor-1.0.1.gemspec +34 -0
  158. metadata +214 -0
@@ -0,0 +1,336 @@
1
+ require_relative "actions/create_file"
2
+ require_relative "actions/create_link"
3
+ require_relative "actions/directory"
4
+ require_relative "actions/empty_directory"
5
+ require_relative "actions/file_manipulation"
6
+ require_relative "actions/inject_into_file"
7
+
8
+ class Thor
9
+ module Actions
10
+ attr_accessor :behavior
11
+
12
+ def self.included(base) #:nodoc:
13
+ super(base)
14
+ base.extend ClassMethods
15
+ end
16
+
17
+ module ClassMethods
18
+ # Hold source paths for one Thor instance. source_paths_for_search is the
19
+ # method responsible to gather source_paths from this current class,
20
+ # inherited paths and the source root.
21
+ #
22
+ def source_paths
23
+ @_source_paths ||= []
24
+ end
25
+
26
+ # Stores and return the source root for this class
27
+ def source_root(path = nil)
28
+ @_source_root = path if path
29
+ @_source_root ||= nil
30
+ end
31
+
32
+ # Returns the source paths in the following order:
33
+ #
34
+ # 1) This class source paths
35
+ # 2) Source root
36
+ # 3) Parents source paths
37
+ #
38
+ def source_paths_for_search
39
+ paths = []
40
+ paths += source_paths
41
+ paths << source_root if source_root
42
+ paths += from_superclass(:source_paths, [])
43
+ paths
44
+ end
45
+
46
+ # Add runtime options that help actions execution.
47
+ #
48
+ def add_runtime_options!
49
+ class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
50
+ :desc => "Overwrite files that already exist"
51
+
52
+ class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
53
+ :desc => "Run but do not make any changes"
54
+
55
+ class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
56
+ :desc => "Suppress status output"
57
+
58
+ class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
59
+ :desc => "Skip files that already exist"
60
+ end
61
+ end
62
+
63
+ # Extends initializer to add more configuration options.
64
+ #
65
+ # ==== Configuration
66
+ # behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
67
+ # It also accepts :force, :skip and :pretend to set the behavior
68
+ # and the respective option.
69
+ #
70
+ # destination_root<String>:: The root directory needed for some actions.
71
+ #
72
+ def initialize(args = [], options = {}, config = {})
73
+ self.behavior = case config[:behavior].to_s
74
+ when "force", "skip"
75
+ _cleanup_options_and_set(options, config[:behavior])
76
+ :invoke
77
+ when "revoke"
78
+ :revoke
79
+ else
80
+ :invoke
81
+ end
82
+
83
+ super
84
+ self.destination_root = config[:destination_root]
85
+ end
86
+
87
+ # Wraps an action object and call it accordingly to the thor class behavior.
88
+ #
89
+ def action(instance) #:nodoc:
90
+ if behavior == :revoke
91
+ instance.revoke!
92
+ else
93
+ instance.invoke!
94
+ end
95
+ end
96
+
97
+ # Returns the root for this thor class (also aliased as destination root).
98
+ #
99
+ def destination_root
100
+ @destination_stack.last
101
+ end
102
+
103
+ # Sets the root for this thor class. Relatives path are added to the
104
+ # directory where the script was invoked and expanded.
105
+ #
106
+ def destination_root=(root)
107
+ @destination_stack ||= []
108
+ @destination_stack[0] = File.expand_path(root || "")
109
+ end
110
+
111
+ # Returns the given path relative to the absolute root (ie, root where
112
+ # the script started).
113
+ #
114
+ def relative_to_original_destination_root(path, remove_dot = true)
115
+ root = @destination_stack[0]
116
+ if path.start_with?(root) && [File::SEPARATOR, File::ALT_SEPARATOR, nil, ''].include?(path[root.size..root.size])
117
+ path = path.dup
118
+ path[0...root.size] = '.'
119
+ remove_dot ? (path[2..-1] || "") : path
120
+ else
121
+ path
122
+ end
123
+ end
124
+
125
+ # Holds source paths in instance so they can be manipulated.
126
+ #
127
+ def source_paths
128
+ @source_paths ||= self.class.source_paths_for_search
129
+ end
130
+
131
+ # Receives a file or directory and search for it in the source paths.
132
+ #
133
+ def find_in_source_paths(file)
134
+ possible_files = [file, file + TEMPLATE_EXTNAME]
135
+ relative_root = relative_to_original_destination_root(destination_root, false)
136
+
137
+ source_paths.each do |source|
138
+ possible_files.each do |f|
139
+ source_file = File.expand_path(f, File.join(source, relative_root))
140
+ return source_file if File.exist?(source_file)
141
+ end
142
+ end
143
+
144
+ message = "Could not find #{file.inspect} in any of your source paths. ".dup
145
+
146
+ unless self.class.source_root
147
+ message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
148
+ end
149
+
150
+ message << if source_paths.empty?
151
+ "Currently you have no source paths."
152
+ else
153
+ "Your current source paths are: \n#{source_paths.join("\n")}"
154
+ end
155
+
156
+ raise Error, message
157
+ end
158
+
159
+ # Do something in the root or on a provided subfolder. If a relative path
160
+ # is given it's referenced from the current root. The full path is yielded
161
+ # to the block you provide. The path is set back to the previous path when
162
+ # the method exits.
163
+ #
164
+ # ==== Parameters
165
+ # dir<String>:: the directory to move to.
166
+ # config<Hash>:: give :verbose => true to log and use padding.
167
+ #
168
+ def inside(dir = "", config = {}, &block)
169
+ verbose = config.fetch(:verbose, false)
170
+ pretend = options[:pretend]
171
+
172
+ say_status :inside, dir, verbose
173
+ shell.padding += 1 if verbose
174
+ @destination_stack.push File.expand_path(dir, destination_root)
175
+
176
+ # If the directory doesnt exist and we're not pretending
177
+ if !File.exist?(destination_root) && !pretend
178
+ require "fileutils"
179
+ FileUtils.mkdir_p(destination_root)
180
+ end
181
+
182
+ if pretend
183
+ # In pretend mode, just yield down to the block
184
+ block.arity == 1 ? yield(destination_root) : yield
185
+ else
186
+ require "fileutils"
187
+ FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
188
+ end
189
+
190
+ @destination_stack.pop
191
+ shell.padding -= 1 if verbose
192
+ end
193
+
194
+ # Goes to the root and execute the given block.
195
+ #
196
+ def in_root
197
+ inside(@destination_stack.first) { yield }
198
+ end
199
+
200
+ # Loads an external file and execute it in the instance binding.
201
+ #
202
+ # ==== Parameters
203
+ # path<String>:: The path to the file to execute. Can be a web address or
204
+ # a relative path from the source root.
205
+ #
206
+ # ==== Examples
207
+ #
208
+ # apply "http://gist.github.com/103208"
209
+ #
210
+ # apply "recipes/jquery.rb"
211
+ #
212
+ def apply(path, config = {})
213
+ verbose = config.fetch(:verbose, true)
214
+ is_uri = path =~ %r{^https?\://}
215
+ path = find_in_source_paths(path) unless is_uri
216
+
217
+ say_status :apply, path, verbose
218
+ shell.padding += 1 if verbose
219
+
220
+ contents = if is_uri
221
+ require "open-uri"
222
+ open(path, "Accept" => "application/x-thor-template", &:read)
223
+ else
224
+ open(path, &:read)
225
+ end
226
+
227
+ instance_eval(contents, path)
228
+ shell.padding -= 1 if verbose
229
+ end
230
+
231
+ # Executes a command returning the contents of the command.
232
+ #
233
+ # ==== Parameters
234
+ # command<String>:: the command to be executed.
235
+ # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
236
+ # to append an executable to command execution.
237
+ #
238
+ # ==== Example
239
+ #
240
+ # inside('vendor') do
241
+ # run('ln -s ~/edge rails')
242
+ # end
243
+ #
244
+ def run(command, config = {})
245
+ return unless behavior == :invoke
246
+
247
+ destination = relative_to_original_destination_root(destination_root, false)
248
+ desc = "#{command} from #{destination.inspect}"
249
+
250
+ if config[:with]
251
+ desc = "#{File.basename(config[:with].to_s)} #{desc}"
252
+ command = "#{config[:with]} #{command}"
253
+ end
254
+
255
+ say_status :run, desc, config.fetch(:verbose, true)
256
+
257
+ return if options[:pretend]
258
+
259
+ env_splat = [config[:env]] if config[:env]
260
+
261
+ if config[:capture]
262
+ require "open3"
263
+ result, status = Open3.capture2e(*env_splat, command.to_s)
264
+ success = status.success?
265
+ else
266
+ result = system(*env_splat, command.to_s)
267
+ success = result
268
+ end
269
+
270
+ abort if !success && config.fetch(:abort_on_failure, self.class.exit_on_failure?)
271
+
272
+ result
273
+ end
274
+
275
+ # Executes a ruby script (taking into account WIN32 platform quirks).
276
+ #
277
+ # ==== Parameters
278
+ # command<String>:: the command to be executed.
279
+ # config<Hash>:: give :verbose => false to not log the status.
280
+ #
281
+ def run_ruby_script(command, config = {})
282
+ return unless behavior == :invoke
283
+ run command, config.merge(:with => Thor::Util.ruby_command)
284
+ end
285
+
286
+ # Run a thor command. A hash of options can be given and it's converted to
287
+ # switches.
288
+ #
289
+ # ==== Parameters
290
+ # command<String>:: the command to be invoked
291
+ # args<Array>:: arguments to the command
292
+ # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
293
+ # Other options are given as parameter to Thor.
294
+ #
295
+ #
296
+ # ==== Examples
297
+ #
298
+ # thor :install, "http://gist.github.com/103208"
299
+ # #=> thor install http://gist.github.com/103208
300
+ #
301
+ # thor :list, :all => true, :substring => 'rails'
302
+ # #=> thor list --all --substring=rails
303
+ #
304
+ def thor(command, *args)
305
+ config = args.last.is_a?(Hash) ? args.pop : {}
306
+ verbose = config.key?(:verbose) ? config.delete(:verbose) : true
307
+ pretend = config.key?(:pretend) ? config.delete(:pretend) : false
308
+ capture = config.key?(:capture) ? config.delete(:capture) : false
309
+
310
+ args.unshift(command)
311
+ args.push Thor::Options.to_switches(config)
312
+ command = args.join(" ").strip
313
+
314
+ run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
315
+ end
316
+
317
+ protected
318
+
319
+ # Allow current root to be shared between invocations.
320
+ #
321
+ def _shared_configuration #:nodoc:
322
+ super.merge!(:destination_root => destination_root)
323
+ end
324
+
325
+ def _cleanup_options_and_set(options, key) #:nodoc:
326
+ case options
327
+ when Array
328
+ %w(--force -f --skip -s).each { |i| options.delete(i) }
329
+ options << "--#{key}"
330
+ when Hash
331
+ [:force, :skip, "force", "skip"].each { |i| options.delete(i) }
332
+ options.merge!(key => true)
333
+ end
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,104 @@
1
+ require_relative "empty_directory"
2
+
3
+ class Thor
4
+ module Actions
5
+ # Create a new file relative to the destination root with the given data,
6
+ # which is the return value of a block or a data string.
7
+ #
8
+ # ==== Parameters
9
+ # destination<String>:: the relative path to the destination root.
10
+ # data<String|NilClass>:: the data to append to the file.
11
+ # config<Hash>:: give :verbose => false to not log the status.
12
+ #
13
+ # ==== Examples
14
+ #
15
+ # create_file "lib/fun_party.rb" do
16
+ # hostname = ask("What is the virtual hostname I should use?")
17
+ # "vhost.name = #{hostname}"
18
+ # end
19
+ #
20
+ # create_file "config/apache.conf", "your apache config"
21
+ #
22
+ def create_file(destination, *args, &block)
23
+ config = args.last.is_a?(Hash) ? args.pop : {}
24
+ data = args.first
25
+ action CreateFile.new(self, destination, block || data.to_s, config)
26
+ end
27
+ alias_method :add_file, :create_file
28
+
29
+ # CreateFile is a subset of Template, which instead of rendering a file with
30
+ # ERB, it gets the content from the user.
31
+ #
32
+ class CreateFile < EmptyDirectory #:nodoc:
33
+ attr_reader :data
34
+
35
+ def initialize(base, destination, data, config = {})
36
+ @data = data
37
+ super(base, destination, config)
38
+ end
39
+
40
+ # Checks if the content of the file at the destination is identical to the rendered result.
41
+ #
42
+ # ==== Returns
43
+ # Boolean:: true if it is identical, false otherwise.
44
+ #
45
+ def identical?
46
+ exists? && File.binread(destination) == render
47
+ end
48
+
49
+ # Holds the content to be added to the file.
50
+ #
51
+ def render
52
+ @render ||= if data.is_a?(Proc)
53
+ data.call
54
+ else
55
+ data
56
+ end
57
+ end
58
+
59
+ def invoke!
60
+ invoke_with_conflict_check do
61
+ require "fileutils"
62
+ FileUtils.mkdir_p(File.dirname(destination))
63
+ File.open(destination, "wb") { |f| f.write render }
64
+ end
65
+ given_destination
66
+ end
67
+
68
+ protected
69
+
70
+ # Now on conflict we check if the file is identical or not.
71
+ #
72
+ def on_conflict_behavior(&block)
73
+ if identical?
74
+ say_status :identical, :blue
75
+ else
76
+ options = base.options.merge(config)
77
+ force_or_skip_or_conflict(options[:force], options[:skip], &block)
78
+ end
79
+ end
80
+
81
+ # If force is true, run the action, otherwise check if it's not being
82
+ # skipped. If both are false, show the file_collision menu, if the menu
83
+ # returns true, force it, otherwise skip.
84
+ #
85
+ def force_or_skip_or_conflict(force, skip, &block)
86
+ if force
87
+ say_status :force, :yellow
88
+ yield unless pretend?
89
+ elsif skip
90
+ say_status :skip, :yellow
91
+ else
92
+ say_status :conflict, :red
93
+ force_or_skip_or_conflict(force_on_collision?, true, &block)
94
+ end
95
+ end
96
+
97
+ # Shows the file collision menu to the user and gets the result.
98
+ #
99
+ def force_on_collision?
100
+ base.shell.file_collision(destination) { render }
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,61 @@
1
+ require_relative "create_file"
2
+
3
+ class Thor
4
+ module Actions
5
+ # Create a new file relative to the destination root from the given source.
6
+ #
7
+ # ==== Parameters
8
+ # destination<String>:: the relative path to the destination root.
9
+ # source<String|NilClass>:: the relative path to the source root.
10
+ # config<Hash>:: give :verbose => false to not log the status.
11
+ # :: give :symbolic => false for hard link.
12
+ #
13
+ # ==== Examples
14
+ #
15
+ # create_link "config/apache.conf", "/etc/apache.conf"
16
+ #
17
+ def create_link(destination, *args)
18
+ config = args.last.is_a?(Hash) ? args.pop : {}
19
+ source = args.first
20
+ action CreateLink.new(self, destination, source, config)
21
+ end
22
+ alias_method :add_link, :create_link
23
+
24
+ # CreateLink is a subset of CreateFile, which instead of taking a block of
25
+ # data, just takes a source string from the user.
26
+ #
27
+ class CreateLink < CreateFile #:nodoc:
28
+ attr_reader :data
29
+
30
+ # Checks if the content of the file at the destination is identical to the rendered result.
31
+ #
32
+ # ==== Returns
33
+ # Boolean:: true if it is identical, false otherwise.
34
+ #
35
+ def identical?
36
+ source = File.expand_path(render, File.dirname(destination))
37
+ exists? && File.identical?(source, destination)
38
+ end
39
+
40
+ def invoke!
41
+ invoke_with_conflict_check do
42
+ require "fileutils"
43
+ FileUtils.mkdir_p(File.dirname(destination))
44
+ # Create a symlink by default
45
+ config[:symbolic] = true if config[:symbolic].nil?
46
+ File.unlink(destination) if exists?
47
+ if config[:symbolic]
48
+ File.symlink(render, destination)
49
+ else
50
+ File.link(render, destination)
51
+ end
52
+ end
53
+ given_destination
54
+ end
55
+
56
+ def exists?
57
+ super || File.symlink?(destination)
58
+ end
59
+ end
60
+ end
61
+ end