bundler-prehistoric 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +100 -0
  5. data/CHANGELOG.md +1640 -0
  6. data/CONTRIBUTING.md +32 -0
  7. data/DEVELOPMENT.md +117 -0
  8. data/Gemfile +3 -0
  9. data/ISSUES.md +96 -0
  10. data/LICENSE.md +23 -0
  11. data/README.md +46 -0
  12. data/Rakefile +256 -0
  13. data/UPGRADING.md +103 -0
  14. data/bin/bundle +21 -0
  15. data/bin/bundle_ruby +56 -0
  16. data/bin/bundler +21 -0
  17. data/bundler.gemspec +33 -0
  18. data/lib/bundler.rb +442 -0
  19. data/lib/bundler/backports/time.rb +7 -0
  20. data/lib/bundler/capistrano.rb +16 -0
  21. data/lib/bundler/cli.rb +395 -0
  22. data/lib/bundler/cli/binstubs.rb +38 -0
  23. data/lib/bundler/cli/cache.rb +34 -0
  24. data/lib/bundler/cli/check.rb +35 -0
  25. data/lib/bundler/cli/clean.rb +19 -0
  26. data/lib/bundler/cli/common.rb +54 -0
  27. data/lib/bundler/cli/config.rb +84 -0
  28. data/lib/bundler/cli/console.rb +39 -0
  29. data/lib/bundler/cli/exec.rb +37 -0
  30. data/lib/bundler/cli/gem.rb +101 -0
  31. data/lib/bundler/cli/init.rb +33 -0
  32. data/lib/bundler/cli/inject.rb +33 -0
  33. data/lib/bundler/cli/install.rb +133 -0
  34. data/lib/bundler/cli/open.rb +23 -0
  35. data/lib/bundler/cli/outdated.rb +80 -0
  36. data/lib/bundler/cli/package.rb +36 -0
  37. data/lib/bundler/cli/platform.rb +43 -0
  38. data/lib/bundler/cli/show.rb +48 -0
  39. data/lib/bundler/cli/update.rb +73 -0
  40. data/lib/bundler/cli/viz.rb +27 -0
  41. data/lib/bundler/constants.rb +5 -0
  42. data/lib/bundler/current_ruby.rb +155 -0
  43. data/lib/bundler/definition.rb +604 -0
  44. data/lib/bundler/dep_proxy.rb +43 -0
  45. data/lib/bundler/dependency.rb +106 -0
  46. data/lib/bundler/deployment.rb +59 -0
  47. data/lib/bundler/deprecate.rb +15 -0
  48. data/lib/bundler/dsl.rb +305 -0
  49. data/lib/bundler/endpoint_specification.rb +76 -0
  50. data/lib/bundler/env.rb +56 -0
  51. data/lib/bundler/environment.rb +42 -0
  52. data/lib/bundler/fetcher.rb +396 -0
  53. data/lib/bundler/friendly_errors.rb +42 -0
  54. data/lib/bundler/gem_helper.rb +169 -0
  55. data/lib/bundler/gem_helpers.rb +25 -0
  56. data/lib/bundler/gem_installer.rb +9 -0
  57. data/lib/bundler/gem_path_manipulation.rb +8 -0
  58. data/lib/bundler/gem_tasks.rb +2 -0
  59. data/lib/bundler/graph.rb +169 -0
  60. data/lib/bundler/index.rb +184 -0
  61. data/lib/bundler/injector.rb +64 -0
  62. data/lib/bundler/installer.rb +332 -0
  63. data/lib/bundler/lazy_specification.rb +83 -0
  64. data/lib/bundler/lockfile_parser.rb +146 -0
  65. data/lib/bundler/match_platform.rb +13 -0
  66. data/lib/bundler/parallel_workers.rb +18 -0
  67. data/lib/bundler/parallel_workers/thread_worker.rb +30 -0
  68. data/lib/bundler/parallel_workers/unix_worker.rb +101 -0
  69. data/lib/bundler/parallel_workers/worker.rb +69 -0
  70. data/lib/bundler/psyched_yaml.rb +26 -0
  71. data/lib/bundler/remote_specification.rb +57 -0
  72. data/lib/bundler/resolver.rb +534 -0
  73. data/lib/bundler/retry.rb +60 -0
  74. data/lib/bundler/ruby_dsl.rb +11 -0
  75. data/lib/bundler/ruby_version.rb +117 -0
  76. data/lib/bundler/rubygems_ext.rb +171 -0
  77. data/lib/bundler/rubygems_integration.rb +578 -0
  78. data/lib/bundler/runtime.rb +310 -0
  79. data/lib/bundler/settings.rb +176 -0
  80. data/lib/bundler/setup.rb +23 -0
  81. data/lib/bundler/shared_helpers.rb +110 -0
  82. data/lib/bundler/similarity_detector.rb +63 -0
  83. data/lib/bundler/source.rb +29 -0
  84. data/lib/bundler/source/git.rb +289 -0
  85. data/lib/bundler/source/git/git_proxy.rb +158 -0
  86. data/lib/bundler/source/path.rb +225 -0
  87. data/lib/bundler/source/path/installer.rb +38 -0
  88. data/lib/bundler/source/rubygems.rb +334 -0
  89. data/lib/bundler/source/svn.rb +260 -0
  90. data/lib/bundler/source/svn/svn_proxy.rb +110 -0
  91. data/lib/bundler/spec_set.rb +154 -0
  92. data/lib/bundler/ssl_certs/.document +1 -0
  93. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  94. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  95. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  96. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  97. data/lib/bundler/ssl_certs/certificate_manager.rb +41 -0
  98. data/lib/bundler/templates/Executable +16 -0
  99. data/lib/bundler/templates/Executable.standalone +12 -0
  100. data/lib/bundler/templates/Gemfile +4 -0
  101. data/lib/bundler/templates/newgem/.travis.yml.tt +3 -0
  102. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  103. data/lib/bundler/templates/newgem/LICENSE.txt.tt +22 -0
  104. data/lib/bundler/templates/newgem/README.md.tt +31 -0
  105. data/lib/bundler/templates/newgem/Rakefile.tt +26 -0
  106. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  107. data/lib/bundler/templates/newgem/consolerc.tt +3 -0
  108. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  109. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  110. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  111. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  112. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  113. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  114. data/lib/bundler/templates/newgem/newgem.gemspec.tt +38 -0
  115. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  116. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  117. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  118. data/lib/bundler/templates/newgem/test/minitest_helper.rb.tt +4 -0
  119. data/lib/bundler/templates/newgem/test/test_newgem.rb.tt +11 -0
  120. data/lib/bundler/ui.rb +7 -0
  121. data/lib/bundler/ui/rg_proxy.rb +21 -0
  122. data/lib/bundler/ui/shell.rb +98 -0
  123. data/lib/bundler/ui/silent.rb +44 -0
  124. data/lib/bundler/vendor/.document +0 -0
  125. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  126. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  127. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  128. data/lib/bundler/vendor/thor.rb +480 -0
  129. data/lib/bundler/vendor/thor/actions.rb +319 -0
  130. data/lib/bundler/vendor/thor/actions/create_file.rb +103 -0
  131. data/lib/bundler/vendor/thor/actions/create_link.rb +59 -0
  132. data/lib/bundler/vendor/thor/actions/directory.rb +118 -0
  133. data/lib/bundler/vendor/thor/actions/empty_directory.rb +135 -0
  134. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +316 -0
  135. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +107 -0
  136. data/lib/bundler/vendor/thor/base.rb +656 -0
  137. data/lib/bundler/vendor/thor/command.rb +133 -0
  138. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  139. data/lib/bundler/vendor/thor/core_ext/io_binary_read.rb +10 -0
  140. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +98 -0
  141. data/lib/bundler/vendor/thor/error.rb +32 -0
  142. data/lib/bundler/vendor/thor/group.rb +281 -0
  143. data/lib/bundler/vendor/thor/invocation.rb +173 -0
  144. data/lib/bundler/vendor/thor/line_editor.rb +17 -0
  145. data/lib/bundler/vendor/thor/line_editor/basic.rb +35 -0
  146. data/lib/bundler/vendor/thor/line_editor/readline.rb +88 -0
  147. data/lib/bundler/vendor/thor/parser.rb +4 -0
  148. data/lib/bundler/vendor/thor/parser/argument.rb +73 -0
  149. data/lib/bundler/vendor/thor/parser/arguments.rb +175 -0
  150. data/lib/bundler/vendor/thor/parser/option.rb +121 -0
  151. data/lib/bundler/vendor/thor/parser/options.rb +218 -0
  152. data/lib/bundler/vendor/thor/rake_compat.rb +71 -0
  153. data/lib/bundler/vendor/thor/runner.rb +322 -0
  154. data/lib/bundler/vendor/thor/shell.rb +81 -0
  155. data/lib/bundler/vendor/thor/shell/basic.rb +420 -0
  156. data/lib/bundler/vendor/thor/shell/color.rb +149 -0
  157. data/lib/bundler/vendor/thor/shell/html.rb +126 -0
  158. data/lib/bundler/vendor/thor/util.rb +267 -0
  159. data/lib/bundler/vendor/thor/version.rb +3 -0
  160. data/lib/bundler/vendored_persistent.rb +3 -0
  161. data/lib/bundler/vendored_thor.rb +8 -0
  162. data/lib/bundler/version.rb +6 -0
  163. data/lib/bundler/vlad.rb +11 -0
  164. data/man/bundle-config.ronn +155 -0
  165. data/man/bundle-exec.ronn +136 -0
  166. data/man/bundle-install.ronn +372 -0
  167. data/man/bundle-package.ronn +59 -0
  168. data/man/bundle-platform.ronn +42 -0
  169. data/man/bundle-update.ronn +179 -0
  170. data/man/bundle.ronn +92 -0
  171. data/man/gemfile.5.ronn +369 -0
  172. data/man/index.txt +7 -0
  173. data/spec/bundler/bundler_spec.rb +74 -0
  174. data/spec/bundler/cli_spec.rb +16 -0
  175. data/spec/bundler/definition_spec.rb +21 -0
  176. data/spec/bundler/dsl_spec.rb +108 -0
  177. data/spec/bundler/friendly_errors_spec.rb +13 -0
  178. data/spec/bundler/gem_helper_spec.rb +225 -0
  179. data/spec/bundler/psyched_yaml_spec.rb +8 -0
  180. data/spec/bundler/retry_spec.rb +59 -0
  181. data/spec/bundler/settings_spec.rb +13 -0
  182. data/spec/bundler/source_spec.rb +25 -0
  183. data/spec/cache/gems_spec.rb +316 -0
  184. data/spec/cache/git_spec.rb +188 -0
  185. data/spec/cache/path_spec.rb +121 -0
  186. data/spec/cache/platform_spec.rb +53 -0
  187. data/spec/cache/svn_spec.rb +82 -0
  188. data/spec/commands/binstubs_spec.rb +246 -0
  189. data/spec/commands/check_spec.rb +278 -0
  190. data/spec/commands/clean_spec.rb +652 -0
  191. data/spec/commands/config_spec.rb +227 -0
  192. data/spec/commands/console_spec.rb +102 -0
  193. data/spec/commands/exec_spec.rb +367 -0
  194. data/spec/commands/help_spec.rb +39 -0
  195. data/spec/commands/init_spec.rb +39 -0
  196. data/spec/commands/inject_spec.rb +78 -0
  197. data/spec/commands/licenses_spec.rb +31 -0
  198. data/spec/commands/newgem_spec.rb +451 -0
  199. data/spec/commands/open_spec.rb +80 -0
  200. data/spec/commands/outdated_spec.rb +168 -0
  201. data/spec/commands/package_spec.rb +128 -0
  202. data/spec/commands/show_spec.rb +152 -0
  203. data/spec/install/binstubs_spec.rb +24 -0
  204. data/spec/install/bundler_spec.rb +146 -0
  205. data/spec/install/deploy_spec.rb +237 -0
  206. data/spec/install/gemfile/gemspec_spec.rb +170 -0
  207. data/spec/install/gemfile/git_spec.rb +967 -0
  208. data/spec/install/gemfile/path_spec.rb +480 -0
  209. data/spec/install/gemfile/svn_spec.rb +582 -0
  210. data/spec/install/gemfile_spec.rb +44 -0
  211. data/spec/install/gems/c_ext_spec.rb +48 -0
  212. data/spec/install/gems/dependency_api_spec.rb +580 -0
  213. data/spec/install/gems/env_spec.rb +107 -0
  214. data/spec/install/gems/flex_spec.rb +314 -0
  215. data/spec/install/gems/groups_spec.rb +308 -0
  216. data/spec/install/gems/mirror_spec.rb +39 -0
  217. data/spec/install/gems/platform_spec.rb +221 -0
  218. data/spec/install/gems/post_install_spec.rb +121 -0
  219. data/spec/install/gems/resolving_spec.rb +124 -0
  220. data/spec/install/gems/simple_case_spec.rb +386 -0
  221. data/spec/install/gems/standalone_spec.rb +260 -0
  222. data/spec/install/gems/sudo_spec.rb +136 -0
  223. data/spec/install/gems/win32_spec.rb +26 -0
  224. data/spec/install/gemspecs_spec.rb +50 -0
  225. data/spec/install/path_spec.rb +150 -0
  226. data/spec/install/post_bundle_message_spec.rb +142 -0
  227. data/spec/install/prereleases_spec.rb +43 -0
  228. data/spec/install/security_policy_spec.rb +77 -0
  229. data/spec/install/upgrade_spec.rb +26 -0
  230. data/spec/lock/git_spec.rb +34 -0
  231. data/spec/lock/lockfile_spec.rb +912 -0
  232. data/spec/lock/svn_spec.rb +35 -0
  233. data/spec/other/bundle_ruby_spec.rb +142 -0
  234. data/spec/other/cli_dispatch_spec.rb +21 -0
  235. data/spec/other/ext_spec.rb +60 -0
  236. data/spec/other/platform_spec.rb +1285 -0
  237. data/spec/other/ssl_cert_spec.rb +10 -0
  238. data/spec/quality_spec.rb +88 -0
  239. data/spec/realworld/dependency_api_spec.rb +60 -0
  240. data/spec/realworld/edgecases_spec.rb +177 -0
  241. data/spec/realworld/parallel_spec.rb +69 -0
  242. data/spec/resolver/basic_spec.rb +66 -0
  243. data/spec/resolver/platform_spec.rb +88 -0
  244. data/spec/runtime/executable_spec.rb +149 -0
  245. data/spec/runtime/load_spec.rb +107 -0
  246. data/spec/runtime/platform_spec.rb +90 -0
  247. data/spec/runtime/require_spec.rb +332 -0
  248. data/spec/runtime/setup_spec.rb +856 -0
  249. data/spec/runtime/with_clean_env_spec.rb +91 -0
  250. data/spec/spec_helper.rb +114 -0
  251. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  252. data/spec/support/artifice/endpoint.rb +71 -0
  253. data/spec/support/artifice/endpoint_500.rb +37 -0
  254. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  255. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  256. data/spec/support/artifice/endpoint_creds_diff_host.rb +38 -0
  257. data/spec/support/artifice/endpoint_extra.rb +31 -0
  258. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  259. data/spec/support/artifice/endpoint_fallback.rb +17 -0
  260. data/spec/support/artifice/endpoint_host_redirect.rb +15 -0
  261. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  262. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  263. data/spec/support/artifice/endpoint_strict_basic_authentication.rb +18 -0
  264. data/spec/support/artifice/endpoint_timeout.rb +13 -0
  265. data/spec/support/builders.rb +748 -0
  266. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  267. data/spec/support/fakeweb/windows.rb +23 -0
  268. data/spec/support/hax.rb +22 -0
  269. data/spec/support/helpers.rb +348 -0
  270. data/spec/support/indexes.rb +280 -0
  271. data/spec/support/less_than_proc.rb +14 -0
  272. data/spec/support/matchers.rb +77 -0
  273. data/spec/support/path.rb +81 -0
  274. data/spec/support/permissions.rb +10 -0
  275. data/spec/support/platforms.rb +94 -0
  276. data/spec/support/ruby_ext.rb +20 -0
  277. data/spec/support/rubygems_ext.rb +39 -0
  278. data/spec/support/streams.rb +13 -0
  279. data/spec/support/sudo.rb +16 -0
  280. data/spec/update/gems_spec.rb +201 -0
  281. data/spec/update/git_spec.rb +236 -0
  282. data/spec/update/source_spec.rb +63 -0
  283. data/spec/update/svn_spec.rb +100 -0
  284. metadata +486 -0
@@ -0,0 +1,319 @@
1
+ require 'fileutils'
2
+ require 'uri'
3
+ require 'thor/core_ext/io_binary_read'
4
+ require 'thor/actions/create_file'
5
+ require 'thor/actions/create_link'
6
+ require 'thor/actions/directory'
7
+ require 'thor/actions/empty_directory'
8
+ require 'thor/actions/file_manipulation'
9
+ require 'thor/actions/inject_into_file'
10
+
11
+ class Thor
12
+ module Actions
13
+ attr_accessor :behavior
14
+
15
+ def self.included(base) #:nodoc:
16
+ base.extend ClassMethods
17
+ end
18
+
19
+ module ClassMethods
20
+ # Hold source paths for one Thor instance. source_paths_for_search is the
21
+ # method responsible to gather source_paths from this current class,
22
+ # inherited paths and the source root.
23
+ #
24
+ def source_paths
25
+ @_source_paths ||= []
26
+ end
27
+
28
+ # Stores and return the source root for this class
29
+ def source_root(path = nil)
30
+ @_source_root = path if path
31
+ @_source_root ||= nil
32
+ end
33
+
34
+ # Returns the source paths in the following order:
35
+ #
36
+ # 1) This class source paths
37
+ # 2) Source root
38
+ # 3) Parents source paths
39
+ #
40
+ def source_paths_for_search
41
+ paths = []
42
+ paths += source_paths
43
+ paths << source_root if source_root
44
+ paths += from_superclass(:source_paths, [])
45
+ paths
46
+ end
47
+
48
+ # Add runtime options that help actions execution.
49
+ #
50
+ def add_runtime_options!
51
+ class_option :force, :type => :boolean, :aliases => '-f', :group => :runtime,
52
+ :desc => 'Overwrite files that already exist'
53
+
54
+ class_option :pretend, :type => :boolean, :aliases => '-p', :group => :runtime,
55
+ :desc => 'Run but do not make any changes'
56
+
57
+ class_option :quiet, :type => :boolean, :aliases => '-q', :group => :runtime,
58
+ :desc => 'Suppress status output'
59
+
60
+ class_option :skip, :type => :boolean, :aliases => '-s', :group => :runtime,
61
+ :desc => 'Skip files that already exist'
62
+ end
63
+ end
64
+
65
+ # Extends initializer to add more configuration options.
66
+ #
67
+ # ==== Configuration
68
+ # behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
69
+ # It also accepts :force, :skip and :pretend to set the behavior
70
+ # and the respective option.
71
+ #
72
+ # destination_root<String>:: The root directory needed for some actions.
73
+ #
74
+ def initialize(args = [], options = {}, config = {})
75
+ self.behavior = case config[:behavior].to_s
76
+ when 'force', 'skip'
77
+ _cleanup_options_and_set(options, config[:behavior])
78
+ :invoke
79
+ when 'revoke'
80
+ :revoke
81
+ else
82
+ :invoke
83
+ end
84
+ super
85
+ self.destination_root = config[:destination_root]
86
+ end
87
+
88
+ # Wraps an action object and call it accordingly to the thor class behavior.
89
+ #
90
+ def action(instance) #:nodoc:
91
+ if behavior == :revoke
92
+ instance.revoke!
93
+ else
94
+ instance.invoke!
95
+ end
96
+ end
97
+
98
+ # Returns the root for this thor class (also aliased as destination root).
99
+ #
100
+ def destination_root
101
+ @destination_stack.last
102
+ end
103
+
104
+ # Sets the root for this thor class. Relatives path are added to the
105
+ # directory where the script was invoked and expanded.
106
+ #
107
+ def destination_root=(root)
108
+ @destination_stack ||= []
109
+ @destination_stack[0] = File.expand_path(root || '')
110
+ end
111
+
112
+ # Returns the given path relative to the absolute root (ie, root where
113
+ # the script started).
114
+ #
115
+ def relative_to_original_destination_root(path, remove_dot = true)
116
+ path = path.dup
117
+ if path.gsub!(@destination_stack[0], '.')
118
+ remove_dot ? (path[2..-1] || '') : path
119
+ else
120
+ path
121
+ end
122
+ end
123
+
124
+ # Holds source paths in instance so they can be manipulated.
125
+ #
126
+ def source_paths
127
+ @source_paths ||= self.class.source_paths_for_search
128
+ end
129
+
130
+ # Receives a file or directory and search for it in the source paths.
131
+ #
132
+ def find_in_source_paths(file) # rubocop:disable MethodLength
133
+ possible_files = [file, file + TEMPLATE_EXTNAME]
134
+ relative_root = relative_to_original_destination_root(destination_root, false)
135
+
136
+ source_paths.each do |source|
137
+ possible_files.each do |f|
138
+ source_file = File.expand_path(f, File.join(source, relative_root))
139
+ return source_file if File.exist?(source_file)
140
+ end
141
+ end
142
+
143
+ message = "Could not find #{file.inspect} in any of your source paths. "
144
+
145
+ unless self.class.source_root
146
+ message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
147
+ end
148
+
149
+ if source_paths.empty?
150
+ message << 'Currently you have no source paths.'
151
+ else
152
+ message << "Your current source paths are: \n#{source_paths.join("\n")}"
153
+ end
154
+
155
+ fail Error, message
156
+ end
157
+
158
+ # Do something in the root or on a provided subfolder. If a relative path
159
+ # is given it's referenced from the current root. The full path is yielded
160
+ # to the block you provide. The path is set back to the previous path when
161
+ # the method exits.
162
+ #
163
+ # ==== Parameters
164
+ # dir<String>:: the directory to move to.
165
+ # config<Hash>:: give :verbose => true to log and use padding.
166
+ #
167
+ def inside(dir = '', config = {}, &block)
168
+ verbose = config.fetch(:verbose, false)
169
+ pretend = options[:pretend]
170
+
171
+ say_status :inside, dir, verbose
172
+ shell.padding += 1 if verbose
173
+ @destination_stack.push File.expand_path(dir, destination_root)
174
+
175
+ # If the directory doesnt exist and we're not pretending
176
+ if !File.exist?(destination_root) && !pretend
177
+ FileUtils.mkdir_p(destination_root)
178
+ end
179
+
180
+ if pretend
181
+ # In pretend mode, just yield down to the block
182
+ block.arity == 1 ? yield(destination_root) : yield
183
+ else
184
+ FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
185
+ end
186
+
187
+ @destination_stack.pop
188
+ shell.padding -= 1 if verbose
189
+ end
190
+
191
+ # Goes to the root and execute the given block.
192
+ #
193
+ def in_root
194
+ inside(@destination_stack.first) { yield }
195
+ end
196
+
197
+ # Loads an external file and execute it in the instance binding.
198
+ #
199
+ # ==== Parameters
200
+ # path<String>:: The path to the file to execute. Can be a web address or
201
+ # a relative path from the source root.
202
+ #
203
+ # ==== Examples
204
+ #
205
+ # apply "http://gist.github.com/103208"
206
+ #
207
+ # apply "recipes/jquery.rb"
208
+ #
209
+ def apply(path, config = {})
210
+ verbose = config.fetch(:verbose, true)
211
+ is_uri = path =~ %r{^https?\://}
212
+ path = find_in_source_paths(path) unless is_uri
213
+
214
+ say_status :apply, path, verbose
215
+ shell.padding += 1 if verbose
216
+
217
+ if is_uri
218
+ contents = open(path, 'Accept' => 'application/x-thor-template') { |io| io.read }
219
+ else
220
+ contents = open(path) { |io| io.read }
221
+ end
222
+
223
+ instance_eval(contents, path)
224
+ shell.padding -= 1 if verbose
225
+ end
226
+
227
+ # Executes a command returning the contents of the command.
228
+ #
229
+ # ==== Parameters
230
+ # command<String>:: the command to be executed.
231
+ # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
232
+ # to append an executable to command execution.
233
+ #
234
+ # ==== Example
235
+ #
236
+ # inside('vendor') do
237
+ # run('ln -s ~/edge rails')
238
+ # end
239
+ #
240
+ def run(command, config = {})
241
+ return unless behavior == :invoke
242
+
243
+ destination = relative_to_original_destination_root(destination_root, false)
244
+ desc = "#{command} from #{destination.inspect}"
245
+
246
+ if config[:with]
247
+ desc = "#{File.basename(config[:with].to_s)} #{desc}"
248
+ command = "#{config[:with]} #{command}"
249
+ end
250
+
251
+ say_status :run, desc, config.fetch(:verbose, true)
252
+
253
+ unless options[:pretend]
254
+ config[:capture] ? `#{command}` : system("#{command}")
255
+ end
256
+ end
257
+
258
+ # Executes a ruby script (taking into account WIN32 platform quirks).
259
+ #
260
+ # ==== Parameters
261
+ # command<String>:: the command to be executed.
262
+ # config<Hash>:: give :verbose => false to not log the status.
263
+ #
264
+ def run_ruby_script(command, config = {})
265
+ return unless behavior == :invoke
266
+ run command, config.merge(:with => Thor::Util.ruby_command)
267
+ end
268
+
269
+ # Run a thor command. A hash of options can be given and it's converted to
270
+ # switches.
271
+ #
272
+ # ==== Parameters
273
+ # command<String>:: the command to be invoked
274
+ # args<Array>:: arguments to the command
275
+ # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
276
+ # Other options are given as parameter to Thor.
277
+ #
278
+ #
279
+ # ==== Examples
280
+ #
281
+ # thor :install, "http://gist.github.com/103208"
282
+ # #=> thor install http://gist.github.com/103208
283
+ #
284
+ # thor :list, :all => true, :substring => 'rails'
285
+ # #=> thor list --all --substring=rails
286
+ #
287
+ def thor(command, *args)
288
+ config = args.last.is_a?(Hash) ? args.pop : {}
289
+ verbose = config.key?(:verbose) ? config.delete(:verbose) : true
290
+ pretend = config.key?(:pretend) ? config.delete(:pretend) : false
291
+ capture = config.key?(:capture) ? config.delete(:capture) : false
292
+
293
+ args.unshift(command)
294
+ args.push Thor::Options.to_switches(config)
295
+ command = args.join(' ').strip
296
+
297
+ run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
298
+ end
299
+
300
+ protected
301
+
302
+ # Allow current root to be shared between invocations.
303
+ #
304
+ def _shared_configuration #:nodoc:
305
+ super.merge!(:destination_root => destination_root)
306
+ end
307
+
308
+ def _cleanup_options_and_set(options, key) #:nodoc:
309
+ case options
310
+ when Array
311
+ %w(--force -f --skip -s).each { |i| options.delete(i) }
312
+ options << "--#{key}"
313
+ when Hash
314
+ [:force, :skip, 'force', 'skip'].each { |i| options.delete(i) }
315
+ options.merge!(key => true)
316
+ end
317
+ end
318
+ end
319
+ end
@@ -0,0 +1,103 @@
1
+ require 'thor/actions/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
+ FileUtils.mkdir_p(File.dirname(destination))
62
+ File.open(destination, 'wb') { |f| f.write render }
63
+ end
64
+ given_destination
65
+ end
66
+
67
+ protected
68
+
69
+ # Now on conflict we check if the file is identical or not.
70
+ #
71
+ def on_conflict_behavior(&block)
72
+ if identical?
73
+ say_status :identical, :blue
74
+ else
75
+ options = base.options.merge(config)
76
+ force_or_skip_or_conflict(options[:force], options[:skip], &block)
77
+ end
78
+ end
79
+
80
+ # If force is true, run the action, otherwise check if it's not being
81
+ # skipped. If both are false, show the file_collision menu, if the menu
82
+ # returns true, force it, otherwise skip.
83
+ #
84
+ def force_or_skip_or_conflict(force, skip, &block)
85
+ if force
86
+ say_status :force, :yellow
87
+ block.call unless pretend?
88
+ elsif skip
89
+ say_status :skip, :yellow
90
+ else
91
+ say_status :conflict, :red
92
+ force_or_skip_or_conflict(force_on_collision?, true, &block)
93
+ end
94
+ end
95
+
96
+ # Shows the file collision menu to the user and gets the result.
97
+ #
98
+ def force_on_collision?
99
+ base.shell.file_collision(destination) { render }
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,59 @@
1
+ require 'thor/actions/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, &block)
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
+ exists? && File.identical?(render, destination)
37
+ end
38
+
39
+ def invoke!
40
+ invoke_with_conflict_check do
41
+ FileUtils.mkdir_p(File.dirname(destination))
42
+ # Create a symlink by default
43
+ config[:symbolic] = true if config[:symbolic].nil?
44
+ File.unlink(destination) if exists?
45
+ if config[:symbolic]
46
+ File.symlink(render, destination)
47
+ else
48
+ File.link(render, destination)
49
+ end
50
+ end
51
+ given_destination
52
+ end
53
+
54
+ def exists?
55
+ super || File.symlink?(destination)
56
+ end
57
+ end
58
+ end
59
+ end