omnibus 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +17 -1
  3. data/.travis.yml +11 -3
  4. data/CHANGELOG.md +39 -1
  5. data/Gemfile +0 -4
  6. data/README.md +10 -8
  7. data/Rakefile +18 -7
  8. data/bin/omnibus +3 -3
  9. data/docs/Building on Windows.md +98 -0
  10. data/features/commands/_deprecated.feature +46 -0
  11. data/features/commands/build.feature +9 -0
  12. data/features/commands/clean.feature +21 -0
  13. data/features/commands/list.feature +16 -0
  14. data/features/commands/new.feature +8 -0
  15. data/features/commands/version.feature +12 -0
  16. data/features/step_definitions/generator_steps.rb +28 -0
  17. data/features/support/env.rb +13 -0
  18. data/lib/omnibus.rb +319 -240
  19. data/lib/omnibus/artifact.rb +16 -0
  20. data/lib/omnibus/build_version.rb +39 -20
  21. data/lib/omnibus/build_version_dsl.rb +136 -0
  22. data/lib/omnibus/builder.rb +28 -23
  23. data/lib/omnibus/cleaner.rb +72 -0
  24. data/lib/omnibus/cli.rb +115 -11
  25. data/lib/omnibus/cli/base.rb +82 -81
  26. data/lib/omnibus/cli/cache.rb +80 -32
  27. data/lib/omnibus/cli/deprecated.rb +79 -0
  28. data/lib/omnibus/cli/release.rb +17 -21
  29. data/lib/omnibus/config.rb +38 -13
  30. data/lib/omnibus/exceptions.rb +70 -18
  31. data/lib/omnibus/fetcher.rb +18 -11
  32. data/lib/omnibus/fetchers/git_fetcher.rb +48 -53
  33. data/lib/omnibus/fetchers/net_fetcher.rb +29 -27
  34. data/lib/omnibus/fetchers/path_fetcher.rb +9 -12
  35. data/lib/omnibus/fetchers/s3_cache_fetcher.rb +5 -8
  36. data/lib/omnibus/generator.rb +131 -0
  37. data/lib/omnibus/{templates → generator_files}/.kitchen.local.yml.erb +0 -0
  38. data/lib/omnibus/{templates → generator_files}/.kitchen.yml.erb +0 -0
  39. data/lib/omnibus/{templates → generator_files}/Berksfile.erb +0 -0
  40. data/lib/omnibus/{templates → generator_files}/Gemfile.erb +2 -2
  41. data/lib/omnibus/{templates → generator_files}/README.md.erb +6 -7
  42. data/lib/omnibus/{templates → generator_files}/Vagrantfile.erb +0 -0
  43. data/lib/omnibus/{templates → generator_files}/gitignore.erb +0 -0
  44. data/lib/omnibus/{templates → generator_files}/mac_dmg/background.png +0 -0
  45. data/lib/omnibus/{templates → generator_files}/mac_dmg/icon.png +0 -0
  46. data/lib/omnibus/{templates → generator_files}/mac_pkg/background.png +0 -0
  47. data/lib/omnibus/{templates → generator_files}/mac_pkg/license.html.erb +0 -0
  48. data/lib/omnibus/{templates → generator_files}/mac_pkg/welcome.html.erb +0 -0
  49. data/lib/omnibus/{templates → generator_files}/omnibus.rb.example.erb +0 -0
  50. data/lib/omnibus/{templates → generator_files}/package_scripts/makeselfinst.erb +0 -0
  51. data/lib/omnibus/{templates → generator_files}/package_scripts/postinst.erb +0 -0
  52. data/lib/omnibus/{templates → generator_files}/package_scripts/postrm.erb +0 -0
  53. data/lib/omnibus/{templates → generator_files}/package_scripts/preinst.erb +0 -0
  54. data/lib/omnibus/{templates → generator_files}/package_scripts/prerm.erb +0 -0
  55. data/lib/omnibus/{templates → generator_files}/project.rb.erb +0 -1
  56. data/lib/omnibus/{templates → generator_files}/software/c-example.rb.erb +0 -0
  57. data/lib/omnibus/{templates → generator_files}/software/erlang-example.rb.erb +0 -0
  58. data/lib/omnibus/{templates → generator_files}/software/ruby-example.rb.erb +0 -0
  59. data/lib/omnibus/generator_files/windows_msi/assets/LICENSE.rtf +8 -0
  60. data/lib/omnibus/generator_files/windows_msi/assets/banner_background.bmp +0 -0
  61. data/lib/omnibus/generator_files/windows_msi/assets/dialog_background.bmp +0 -0
  62. data/lib/omnibus/generator_files/windows_msi/assets/project.ico +0 -0
  63. data/lib/omnibus/generator_files/windows_msi/assets/project_16x16.ico +0 -0
  64. data/lib/omnibus/generator_files/windows_msi/assets/project_32x32.ico +0 -0
  65. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +20 -0
  66. data/lib/omnibus/generator_files/windows_msi/parameters.wxi.erb +9 -0
  67. data/lib/omnibus/generator_files/windows_msi/source.wxs.erb +74 -0
  68. data/lib/omnibus/health_check.rb +80 -40
  69. data/lib/omnibus/install_path_cache.rb +11 -12
  70. data/lib/omnibus/library.rb +30 -3
  71. data/lib/omnibus/logger.rb +47 -0
  72. data/lib/omnibus/logging.rb +60 -0
  73. data/lib/omnibus/null_builder.rb +23 -0
  74. data/lib/omnibus/ohai.rb +70 -0
  75. data/lib/omnibus/overrides.rb +69 -48
  76. data/lib/omnibus/package_release.rb +7 -14
  77. data/lib/omnibus/packagers/base.rb +66 -13
  78. data/lib/omnibus/packagers/mac_dmg.rb +23 -3
  79. data/lib/omnibus/packagers/mac_pkg.rb +20 -10
  80. data/lib/omnibus/packagers/windows_msi.rb +109 -0
  81. data/lib/omnibus/project.rb +136 -79
  82. data/lib/omnibus/reports.rb +1 -2
  83. data/lib/omnibus/{s3_cacher.rb → s3_cache.rb} +15 -37
  84. data/lib/omnibus/software.rb +77 -27
  85. data/lib/omnibus/software_s3_urls.rb +50 -0
  86. data/lib/omnibus/sugar.rb +1 -3
  87. data/lib/omnibus/util.rb +45 -18
  88. data/lib/omnibus/version.rb +2 -3
  89. data/omnibus.gemspec +5 -3
  90. data/spec/data/complicated/config/patches/bzip2/makefile_take_env_vars.patch +15 -0
  91. data/spec/data/complicated/config/patches/couchdb/patch_for_couchjs_stack.patch +19 -0
  92. data/spec/data/complicated/config/patches/gd/gd-2.0.33-configure-libpng.patch +100 -0
  93. data/spec/data/complicated/config/patches/keepalived/keepalived-1.2.9_opscode_centos_5.patch +15 -0
  94. data/spec/data/complicated/config/patches/libedit/freebsd-vi-fix.patch +24 -0
  95. data/spec/data/complicated/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch +29 -0
  96. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-makefile-dest-fix.patch +35 -0
  97. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-malloc-fix.patch +13 -0
  98. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-shared_lib_plus_plus-1.patch +1035 -0
  99. data/spec/data/complicated/config/patches/logrotate/logrotate_basedir_override.patch +12 -0
  100. data/spec/data/complicated/config/patches/ncurses/ncurses-5.9-solaris-xopen_source_extended-detection.patch +11 -0
  101. data/spec/data/complicated/config/patches/ncurses/ncurses-clang.patch +42 -0
  102. data/spec/data/complicated/config/patches/ncurses/patch-aa +23 -0
  103. data/spec/data/complicated/config/patches/ncurses/patch-ab +44 -0
  104. data/spec/data/complicated/config/patches/ncurses/patch-ac +40 -0
  105. data/spec/data/complicated/config/patches/ncurses/patch-ad +12 -0
  106. data/spec/data/complicated/config/patches/ncurses/patch-aix-configure +23 -0
  107. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesf.h +22 -0
  108. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesm.h +22 -0
  109. data/spec/data/complicated/config/patches/nrpe/fix_for_runit.patch +64 -0
  110. data/spec/data/complicated/config/patches/openssl/openssl-1.0.1f-do-not-build-docs.patch +101 -0
  111. data/spec/data/complicated/config/patches/postgresql/postgresql-9.1.2-configure-ncurses-fix.patch +12 -0
  112. data/spec/data/complicated/config/patches/ruby/patch-configure +103 -0
  113. data/spec/data/complicated/config/patches/ruby/ruby-aix-configure.patch +10 -0
  114. data/spec/data/complicated/config/patches/ruby/ruby-openssl-1.0.1c.patch +42 -0
  115. data/spec/data/complicated/config/patches/ruby/ruby_aix_1_9_3_448_ssl_EAGAIN.patch +57 -0
  116. data/spec/data/complicated/config/patches/ruby/rvm-cflags.patch +27 -0
  117. data/spec/data/complicated/config/projects/angrychef.rb +32 -0
  118. data/spec/data/complicated/config/projects/chef-windows.rb +32 -0
  119. data/spec/data/complicated/config/projects/chef.rb +32 -0
  120. data/spec/data/complicated/config/projects/chefdk-windows.rb +41 -0
  121. data/spec/data/complicated/config/projects/chefdk.rb +44 -0
  122. data/spec/data/complicated/config/software/appbundler.rb +25 -0
  123. data/spec/data/complicated/config/software/autoconf.rb +35 -0
  124. data/spec/data/complicated/config/software/automake.rb +39 -0
  125. data/spec/data/complicated/config/software/berkshelf.rb +44 -0
  126. data/{lib/omnibus/fetchers.rb → spec/data/complicated/config/software/bundler.rb} +8 -5
  127. data/spec/data/complicated/config/software/bzip2.rb +46 -0
  128. data/spec/data/complicated/config/software/cacerts.rb +44 -0
  129. data/spec/data/complicated/config/software/chef-client-msi.rb +88 -0
  130. data/spec/data/complicated/config/software/chef-gem.rb +26 -0
  131. data/spec/data/complicated/config/software/chef-vault.rb +43 -0
  132. data/spec/data/complicated/config/software/chef-windows.rb +158 -0
  133. data/spec/data/complicated/config/software/chef.rb +170 -0
  134. data/spec/data/complicated/config/software/chefdk.rb +103 -0
  135. data/spec/data/complicated/config/software/couchdb.rb +53 -0
  136. data/spec/data/complicated/config/software/curl.rb +48 -0
  137. data/spec/data/complicated/config/software/erlang.rb +65 -0
  138. data/spec/data/complicated/config/software/expat.rb +21 -0
  139. data/spec/data/complicated/config/software/fcgi.rb +56 -0
  140. data/spec/data/complicated/config/software/fcgiwrap.rb +41 -0
  141. data/spec/data/complicated/config/software/gd.rb +56 -0
  142. data/spec/data/complicated/config/software/gdbm.rb +40 -0
  143. data/spec/data/complicated/config/software/gecode.rb +48 -0
  144. data/spec/data/complicated/config/software/git.rb +40 -0
  145. data/spec/data/complicated/config/software/help2man.rb +30 -0
  146. data/spec/data/complicated/config/software/icu.rb +40 -0
  147. data/spec/data/complicated/config/software/jre.rb +48 -0
  148. data/spec/data/complicated/config/software/keepalived.rb +43 -0
  149. data/spec/data/complicated/config/software/libarchive.rb +50 -0
  150. data/spec/data/complicated/config/software/libedit.rb +69 -0
  151. data/spec/data/complicated/config/software/libffi.rb +71 -0
  152. data/spec/data/complicated/config/software/libgcc.rb +39 -0
  153. data/spec/data/complicated/config/software/libiconv.rb +66 -0
  154. data/spec/data/complicated/config/software/libjpeg.rb +39 -0
  155. data/spec/data/complicated/config/software/libpng.rb +38 -0
  156. data/spec/data/complicated/config/software/libtool.rb +52 -0
  157. data/spec/data/complicated/config/software/libwrap.rb +50 -0
  158. data/spec/data/complicated/config/software/libxml2.rb +51 -0
  159. data/spec/data/complicated/config/software/libxslt.rb +52 -0
  160. data/spec/data/complicated/config/software/libyaml-windows.rb +43 -0
  161. data/spec/data/complicated/config/software/libyaml.rb +62 -0
  162. data/spec/data/complicated/config/software/logrotate.rb +41 -0
  163. data/spec/data/complicated/config/software/makedepend.rb +73 -0
  164. data/spec/data/complicated/config/software/mysql2.rb +42 -0
  165. data/spec/data/complicated/config/software/nagios-plugins.rb +53 -0
  166. data/spec/data/complicated/config/software/nagios.rb +66 -0
  167. data/spec/data/complicated/config/software/ncurses.rb +149 -0
  168. data/spec/data/complicated/config/software/nginx.rb +40 -0
  169. data/spec/data/complicated/config/software/nodejs.rb +44 -0
  170. data/spec/data/complicated/config/software/nokogiri.rb +55 -0
  171. data/spec/data/complicated/config/software/nrpe.rb +61 -0
  172. data/spec/data/complicated/config/software/ohai.rb +64 -0
  173. data/spec/data/complicated/config/software/omnibus-ctl.rb +34 -0
  174. data/spec/data/complicated/config/software/openresty.rb +67 -0
  175. data/spec/data/complicated/config/software/openssl.rb +158 -0
  176. data/spec/data/complicated/config/software/pcre.rb +42 -0
  177. data/spec/data/complicated/config/software/perl-extutils-embed.rb +15 -0
  178. data/spec/data/complicated/config/software/perl-extutils-makemaker.rb +15 -0
  179. data/spec/data/complicated/config/software/perl.rb +48 -0
  180. data/spec/data/complicated/config/software/perl_pg_driver.rb +12 -0
  181. data/spec/data/complicated/config/software/php.rb +41 -0
  182. data/spec/data/complicated/config/software/pip.rb +30 -0
  183. data/spec/data/complicated/config/software/pkg-config.rb +66 -0
  184. data/spec/data/complicated/config/software/popt.rb +47 -0
  185. data/spec/data/complicated/config/software/postgresql.rb +51 -0
  186. data/spec/data/complicated/config/software/preparation.rb +30 -0
  187. data/spec/data/complicated/config/software/pygments.rb +25 -0
  188. data/spec/data/complicated/config/software/python.rb +49 -0
  189. data/spec/data/complicated/config/software/rabbitmq.rb +36 -0
  190. data/spec/data/complicated/config/software/rebar.rb +36 -0
  191. data/spec/data/complicated/config/software/redis.rb +33 -0
  192. data/spec/data/complicated/config/software/rsync.rb +48 -0
  193. data/spec/data/complicated/config/software/ruby-windows-devkit.rb +30 -0
  194. data/spec/data/complicated/config/software/ruby-windows.rb +30 -0
  195. data/spec/data/complicated/config/software/ruby.rb +162 -0
  196. data/spec/data/complicated/config/software/rubygems-customization.rb +57 -0
  197. data/spec/data/complicated/config/software/rubygems.rb +37 -0
  198. data/spec/data/complicated/config/software/runit.rb +118 -0
  199. data/spec/data/complicated/config/software/server-jre.rb +46 -0
  200. data/spec/data/complicated/config/software/setuptools.rb +30 -0
  201. data/spec/data/complicated/config/software/spawn-fcgi.rb +40 -0
  202. data/spec/data/complicated/config/software/sphinx.rb +26 -0
  203. data/spec/data/complicated/config/software/spidermonkey.rb +60 -0
  204. data/spec/data/complicated/config/software/sqitch.rb +24 -0
  205. data/spec/data/complicated/config/software/test-kitchen.rb +39 -0
  206. data/spec/data/complicated/config/software/unicorn.rb +27 -0
  207. data/spec/data/complicated/config/software/util-macros.rb +46 -0
  208. data/spec/data/complicated/config/software/version-manifest.rb +32 -0
  209. data/spec/data/complicated/config/software/xproto.rb +46 -0
  210. data/spec/data/complicated/config/software/yajl.rb +30 -0
  211. data/spec/data/complicated/config/software/zlib.rb +67 -0
  212. data/spec/data/projects/chefdk.rb +4 -4
  213. data/spec/data/projects/sample.rb +3 -0
  214. data/spec/data/software/erchef.rb +1 -1
  215. data/spec/fixtures/sample/files/windows_msi/Resources/assets/LICENSE.rtf +8 -0
  216. data/spec/fixtures/sample/files/windows_msi/Resources/assets/banner_background.bmp +0 -0
  217. data/spec/fixtures/sample/files/windows_msi/Resources/assets/dialog_background.bmp +0 -0
  218. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project.ico +0 -0
  219. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_16x16.ico +0 -0
  220. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_32x32.ico +0 -0
  221. data/spec/fixtures/sample/files/windows_msi/Resources/localization-en-us.wxl +20 -0
  222. data/spec/fixtures/sample/files/windows_msi/Resources/parameters.wxi.erb +9 -0
  223. data/spec/fixtures/sample/files/windows_msi/Resources/source.wxs +74 -0
  224. data/spec/functional/packagers/mac_spec.rb +3 -20
  225. data/spec/functional/packagers/windows_spec.rb +69 -0
  226. data/spec/spec_helper.rb +79 -1
  227. data/spec/unit/artifact_spec.rb +0 -18
  228. data/spec/unit/build_version_dsl_spec.rb +136 -0
  229. data/spec/unit/build_version_spec.rb +185 -198
  230. data/spec/unit/config_spec.rb +18 -1
  231. data/spec/unit/fetchers/git_fetcher_spec.rb +55 -80
  232. data/spec/unit/fetchers/net_fetcher_spec.rb +11 -21
  233. data/spec/unit/install_path_cache_spec.rb +164 -136
  234. data/spec/unit/library_spec.rb +125 -5
  235. data/spec/unit/omnibus_spec.rb +25 -9
  236. data/spec/unit/overrides_spec.rb +2 -14
  237. data/spec/unit/package_release_spec.rb +0 -18
  238. data/spec/unit/packagers/base_spec.rb +84 -21
  239. data/spec/unit/packagers/mac_pkg_spec.rb +34 -24
  240. data/spec/unit/project_spec.rb +100 -102
  241. data/spec/unit/s3_cacher_spec.rb +0 -18
  242. data/spec/unit/software_spec.rb +152 -6
  243. data/spec/{sugar_spec.rb → unit/sugar_spec.rb} +0 -3
  244. metadata +365 -38
  245. data/lib/omnibus/cli/application.rb +0 -147
  246. data/lib/omnibus/cli/build.rb +0 -64
@@ -1,6 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
3
- # License:: Apache License, Version 2.0
2
+ # Copyright 2014 Chef Software, Inc.
4
3
  #
5
4
  # Licensed under the Apache License, Version 2.0 (the "License");
6
5
  # you may not use this file except in compliance with the License.
@@ -15,19 +14,124 @@
15
14
  # limitations under the License.
16
15
  #
17
16
 
18
- require 'omnibus/cli/application'
19
- require 'omnibus/cli/base'
20
- require 'omnibus/cli/build'
17
+ require 'thor'
18
+ require 'omnibus'
21
19
 
22
20
  module Omnibus
23
- module CLI
24
- class Error < StandardError
25
- attr_reader :original
21
+ class CLI < Command::Base
22
+ # This is the main entry point for the CLI. It exposes the method
23
+ # {#execute!} to start the CLI.
24
+ #
25
+ # @note the arity of {#initialize} and {#execute!} are extremely important
26
+ # for testing purposes. It is a requirement to perform in-process testing
27
+ # with Aruba. In process testing is much faster than spawning a new Ruby
28
+ # process for each test.
29
+ class Runner
30
+ include Logging
26
31
 
27
- def initialize(msg, original = nil)
28
- super(msg)
29
- @original = original
32
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
33
+ @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
30
34
  end
35
+
36
+ def execute!
37
+ $stdin = @stdin
38
+ $stdout = @stdout
39
+ $stderr = @stderr
40
+
41
+ Omnibus::CLI.start(@argv)
42
+ @kernel.exit(0)
43
+ rescue => e
44
+ error = Omnibus.ui.set_color(e.message, :red)
45
+ Omnibus.ui.error(error)
46
+
47
+ if log.debug?
48
+ backtrace = Omnibus.ui.set_color("\n" + e.backtrace.join("\n "), :red)
49
+ Omnibus.ui.error(backtrace)
50
+ end
51
+
52
+ if e.respond_to?(:status_code)
53
+ @kernel.exit(e.status_code)
54
+ else
55
+ @kernel.exit(1)
56
+ end
57
+ end
58
+ end
59
+
60
+ map %w(-v --version) => 'version'
61
+
62
+ #
63
+ # Build an Omnibus project or software definition.
64
+ #
65
+ # $ omnibus build chefdk
66
+ #
67
+ # @todo Support regular expressions (+$ omnibus build chef*+)
68
+ #
69
+ desc 'build PROJECT', 'Build the given Omnibus project'
70
+ def build(name)
71
+ project = Omnibus.project(name)
72
+ raise ProjectNotFound.new(name) unless project
73
+
74
+ say("Building #{project.name} #{project.build_version}...")
75
+ project.build_me
76
+ end
77
+
78
+ #
79
+ # Perform cache management functions.
80
+ #
81
+ # $ omnibus cache list
82
+ #
83
+ register(Command::Cache, 'cache', 'cache [COMMAND]', 'Manage the cache')
84
+ CLI.tasks['cache'].options = Command::Cache.class_options
85
+
86
+ #
87
+ # Clean the Omnibus project.
88
+ #
89
+ # $ omnibus clean chefdk
90
+ #
91
+ register(Cleaner, 'clean', 'clean PROJECT', 'Clean the Omnibus project')
92
+ CLI.tasks['clean'].options = Cleaner.class_options
93
+
94
+ #
95
+ # Initialize a new Omnibus project.
96
+ #
97
+ # $ omnibus new NAME
98
+ #
99
+ register(Generator, 'new', 'new NAME', 'Initialize a new Omnibus project')
100
+ CLI.tasks['new'].options = Generator.class_options
101
+
102
+ #
103
+ # List the Omnibus projects available from "here".
104
+ #
105
+ # $ omnibus list
106
+ #
107
+ desc 'list', 'List the Omnibus projects'
108
+ def list
109
+ if Omnibus.projects.empty?
110
+ say('There are no Omnibus projects!')
111
+ else
112
+ say('Omnibus projects:')
113
+ Omnibus.projects.sort.each do |project|
114
+ say(" * #{project.name} (#{project.build_version})")
115
+ end
116
+ end
117
+ end
118
+
119
+ #
120
+ # Publish Omnibus package(s) to a backend.
121
+ #
122
+ # $ omnibus release --project chefdk
123
+ #
124
+ register(Command::Release, 'release', 'release', 'Publish Omnibus packages')
125
+ CLI.tasks['clean'].options = Command::Release.class_options
126
+
127
+ #
128
+ # Display version information.
129
+ #
130
+ # $ omnibus version
131
+ #
132
+ desc 'version', 'Display version information', hide: true
133
+ def version
134
+ say("Omnibus v#{Omnibus::VERSION}")
31
135
  end
32
136
  end
33
137
  end
@@ -1,6 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
3
- # License:: Apache License, Version 2.0
2
+ # Copyright 2013-2014 Chef Software, Inc.
4
3
  #
5
4
  # Licensed under the Apache License, Version 2.0 (the "License");
6
5
  # you may not use this file except in compliance with the License.
@@ -15,101 +14,103 @@
15
14
  # limitations under the License.
16
15
  #
17
16
 
18
- require 'omnibus/util'
19
- require 'thor'
20
-
17
+ #
18
+ # This is the base class that all commands and subcommands should extend from.
19
+ # It handles all of the Thor nastiness and method mutating, as well as defining
20
+ # the global configuration options.
21
+ #
21
22
  module Omnibus
22
- module CLI
23
- class Base < Thor
24
- include Thor::Actions
25
-
26
- class_option :config,
27
- aliases: [:c],
28
- type: :string,
29
- default: File.join(Dir.pwd, Omnibus::DEFAULT_CONFIG_FILENAME),
30
- desc: 'Path to the Omnibus configuration file to use.'
31
-
32
- def initialize(args, options, config)
33
- super(args, options, config)
34
- $stdout.sync = true
35
-
36
- # Don't try to initialize the Omnibus project for help commands.#
37
- # current_task renamed to current_command in Thor 0.18.0
38
- current_command = config[:current_command] ? config[:current_command].name : config[:current_task].name
39
- return if current_command == 'help'
40
-
41
- if (config = @options[:config])
42
- if config && File.exist?(@options[:config])
43
- say("Using Omnibus configuration file #{config}", :green)
44
- Omnibus.load_configuration(config)
45
- elsif config
46
- say("No configuration file `#{config}', using defaults", :yellow)
47
- end
23
+ class Command::Base < Thor
24
+ class << self
25
+ def dispatch(m, args, options, config)
26
+ # Handle the case where Thor thinks a trailing --help is actually an
27
+ # argument and blows up...
28
+ if args.length > 1 && !(args & Thor::HELP_MAPPINGS).empty?
29
+ args.unshift('help')
48
30
  end
49
31
 
50
- if (path = @options[:path])
51
- # TODO: merge in all relevant CLI options here, as they should
52
- # override anything from a configuration file.
53
- Omnibus::Config.project_root(path)
54
- Omnibus::Config.append_timestamp(@options[:timestamp]) if @options.key?('timestamp')
55
-
56
- unless Omnibus.project_files.any?
57
- fail Omnibus::CLI::Error, "Given path '#{path}' does not appear to be a valid Omnibus project root."
58
- end
59
-
60
- begin
61
- Omnibus.process_configuration
62
- rescue => e
63
- error_msg = 'Could not load the Omnibus projects.'
64
- raise Omnibus::CLI::Error.new(error_msg, e)
65
- end
66
- end
32
+ super
67
33
  end
34
+ end
35
+
36
+ include Logging
68
37
 
69
- ##################################################################
70
- # Thor Overrides/Tweaks
71
- ##################################################################
38
+ def initialize(args, options, config)
39
+ super(args, options, config)
72
40
 
73
- # Used by {Thor::Actions#template} to locate ERB templates
74
- # @return [String]
75
- def self.source_root
76
- File.expand_path(File.join(File.dirname(__FILE__), '..', 'templates'))
41
+ # Set the log_level
42
+ if @options[:log_level]
43
+ Omnibus.logger.level = @options[:log_level]
77
44
  end
78
45
 
79
- # Forces command to exit with a 1 on any failure...so raise away.
80
- def self.exit_on_failure?
81
- true
46
+ # Do not load the Omnibus config if we are asking for help or the version
47
+ if %w(help version).include?(config[:current_command].name)
48
+ log.debug { 'Skipping Omnibus loading (detected help or version)' }
49
+ return
82
50
  end
83
51
 
84
- # For some strange reason the +subcommand+ argument is disregarded when
85
- # +Thor.banner+ is called by +Thor.command_help+:
86
- #
87
- # https://github.com/wycats/thor/blob/master/lib/thor.rb#L163-L164
88
- #
89
- # We'll override +Thor.banner+ and ensure subcommand is true when called
90
- # for subcommands.
91
- def self.banner(command, namespace = nil, subcommand = false)
92
- # Main commands have an effective namespace of 'application' OR
93
- # contain subcommands
94
- subcommand = self.namespace.split(':').last != 'application' || subcommands.empty?
95
- "#{basename} #{command.formatted_usage(self, $thor_runner, subcommand) }"
52
+ if File.exist?(@options[:config])
53
+ log.info { "Using config from '#{@options[:config]}'" }
54
+ Omnibus.load_configuration(@options[:config])
55
+ else
56
+ if @options[:config] == Omnibus::DEFAULT_CONFIG
57
+ log.debug { 'Config file not given - using defaults' }
58
+ else
59
+ raise "The given config file '#{@options[:config]}' does not exist!"
60
+ end
96
61
  end
97
62
 
98
- protected
63
+ @options[:override].each do |key, value|
64
+ if %w(true false nil).include?(value)
65
+ log.debug { "Detected #{value.inspect} should be an object" }
66
+ value = { 'true' => true, 'false' => false, 'nil' => nil }[value]
67
+ end
99
68
 
100
- ##################################################################
101
- # Omnibus Helpers (should these be in Omnibus::Util?)
102
- ##################################################################
69
+ if value =~ /\A[[:digit:]]+\Z/
70
+ log.debug { "Detected #{value.inspect} should be an integer" }
71
+ value = value.to_i
72
+ end
103
73
 
104
- def load_project!(project_name)
105
- project = Omnibus.project(project_name)
106
- unless project
107
- error_msg = "I don't know anything about project '#{project_name}'."
108
- error_msg << " Valid project names include: #{Omnibus.project_names.join(', ') }"
109
- fail Omnibus::CLI::Error, error_msg
74
+ if Config.respond_to?(key)
75
+ log.debug { "Setting Config.#{key} = #{value.inspect}" }
76
+ Config.send(key, value)
77
+ else
78
+ log.debug { "Skipping option '#{key}' - not a config option" }
110
79
  end
111
- project
112
80
  end
81
+
82
+ log.debug { 'Processing Omnibus configuration...' }
83
+ Omnibus.process_configuration
84
+ end
85
+
86
+ class_option :config,
87
+ desc: 'Path to the Omnibus config file',
88
+ aliases: '-c',
89
+ type: :string,
90
+ default: Omnibus::DEFAULT_CONFIG
91
+ class_option :log_level,
92
+ desc: 'The log level',
93
+ aliases: '-l',
94
+ type: :string,
95
+ enum: %w(fatal error warn info debug),
96
+ lazy_default: 'warn'
97
+ class_option :override,
98
+ desc: 'Override one or more Omnibus config options',
99
+ aliases: '-o',
100
+ type: :hash,
101
+ default: {}
102
+
103
+ #
104
+ # Hide the default help task to encourage people to use +-h+ instead of
105
+ # Thor's dumb way of asking for help.
106
+ #
107
+ desc 'help [COMMAND]', 'Show help output', hide: true
108
+ def help(*)
109
+ super
113
110
  end
114
111
  end
115
112
  end
113
+
114
+ # Include the deprecations from previous versions of Omnibus. This should be
115
+ # removed in the next major version of Omnibus.
116
+ require_relative 'deprecated'
@@ -1,6 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
3
- # License:: Apache License, Version 2.0
2
+ # Copyright 2013-2014 Chef Software, Inc.
4
3
  #
5
4
  # Licensed under the Apache License, Version 2.0 (the "License");
6
5
  # you may not use this file except in compliance with the License.
@@ -15,44 +14,93 @@
15
14
  # limitations under the License.
16
15
  #
17
16
 
18
- require 'omnibus/cli/base'
19
- require 'omnibus/s3_cacher'
20
-
21
17
  module Omnibus
22
- module CLI
23
- class Cache < Base
24
- class_option :path,
25
- aliases: [:p],
26
- type: :string,
27
- default: Dir.pwd,
28
- desc: 'Path to the Omnibus project root.'
29
-
30
- namespace :cache
31
-
32
- desc 'existing', 'List source packages which exist in the cache'
33
- def existing
34
- S3Cache.new.list.each { |s| puts s.name }
35
- end
18
+ class Command::Cache < Command::Base
19
+ namespace :cache
36
20
 
37
- desc 'list', 'List all cached files (by S3 key)'
38
- def list
39
- S3Cache.new.list_by_key.each { |k| puts k }
40
- end
21
+ #
22
+ # List the existing source packages in the cache.
23
+ #
24
+ # $ omnibus cache existing
25
+ #
26
+ desc 'existing', 'List source packages which exist in the cache'
27
+ def existing
28
+ result = cache.list
41
29
 
42
- desc 'missing', 'Lists source packages that are required but not yet cached'
43
- def missing
44
- S3Cache.new.missing.each { |s| puts s.name }
30
+ if result.empty?
31
+ say('There are no packages in the cache!')
32
+ else
33
+ say('The following packages are in the cache:')
34
+ result.each do |source|
35
+ say(" * #{source.name}")
36
+ end
45
37
  end
38
+ end
46
39
 
47
- desc 'fetch', 'Fetches missing source packages to local tmp dir'
48
- def fetch
49
- S3Cache.new.fetch_missing
40
+ #
41
+ # List all cached files (by S3 key).
42
+ #
43
+ # $ omnibus cache list
44
+ #
45
+ desc 'list', 'List all cached files (by S3 key)'
46
+ def list
47
+ result = cache.list_by_key
48
+
49
+ if result.empty?
50
+ say('There is nothing in the cache!')
51
+ else
52
+ say('Cached files (by S3 key):')
53
+ result.each do |key|
54
+ say(" * #{key}")
55
+ end
50
56
  end
57
+ end
58
+
59
+ #
60
+ # List missing source packages.
61
+ #
62
+ # $ omnibus cache missing
63
+ #
64
+ desc 'missing', 'Lists source packages that are required but not yet cached'
65
+ def missing
66
+ result = cache.missing
51
67
 
52
- desc 'populate', 'Populate the S3 Cache'
53
- def populate
54
- S3Cache.new.populate
68
+ if result.empty?
69
+ say('There are no missing packages in the cache.')
70
+ else
71
+ say('The following packages are missing from the cache:')
72
+ result.each do |source|
73
+ say(source.name)
74
+ end
55
75
  end
56
76
  end
77
+
78
+ #
79
+ # Fetch missing source packages locally
80
+ #
81
+ # $ omnibus cache fetch
82
+ #
83
+ desc 'fetch', 'Fetches missing source packages locally'
84
+ def fetch
85
+ say('Fetching missing packages...')
86
+ cache.fetch_missing
87
+ end
88
+
89
+ #
90
+ # Populate the remote S3 cache from local.
91
+ #
92
+ # $ omnibus cache populate
93
+ #
94
+ desc 'populate', 'Populate the S3 Cache'
95
+ def populate
96
+ say('Populating the cache...')
97
+ cache.populate
98
+ end
99
+
100
+ private
101
+
102
+ def cache
103
+ @cache ||= S3Cache.new
104
+ end
57
105
  end
58
106
  end