diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7baf8b1987..f9b58c9a3b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -320,6 +320,7 @@ The following methods may be called to generate standard warning messages: | `reboot` | The user should reboot to complete installation | `files_in_usr_local` | The Cask installs files to `/usr/local`, which may confuse Homebrew | `arch_only(list)` | The Cask only supports certain architectures. Currently valid elements of `list` are `intel-32` and `intel-64` +| `os_version_only(list)` | The Cask only supports certain OS X Versions. Currently valid elements of `list` are `10.5`, `10.6`, `10.7`, `10.8`, and `10.9` Example: diff --git a/lib/cask/caveats.rb b/lib/cask/caveats.rb index 1c07fa6313..ab79ebe72f 100644 --- a/lib/cask/caveats.rb +++ b/lib/cask/caveats.rb @@ -104,6 +104,32 @@ class Cask::CaveatsDSL end end + # minor bug: because output from os_version_only is conditional, the + # existence of this directive causes the "===> Caveats" header to + # appear even if no warning is output. One workaround would + # be to spin out os-version-detection from caveats into a separate + # Cask stanza, and that is probably a sensible design. + def os_versions_only(*supported_versions) + known_versions = %w{10.0 10.1 10.2 10.3 10.3 10.5 10.6 10.7 10.8 10.9} + supported_versions.each do |version| + unless known_versions.include?(version) + # There ought to be some standard exceptions for Cask validation errors + raise "The only valid arguments to caveats os_version_only in #{@cask} are: #{known_versions.join(', ')}" + end + end + unless supported_versions.include?(MACOS_VERSION) + puts <<-EOS.undent + Cask #{@cask} provides binaries for these OS versions: #{supported_versions.join(', ')}. + But you appear to be running on an unsupported version + + #{MACOS_VERSION} + + Therefore #{@cask} is not expected to work on your system. + + EOS + end + end + def method_missing(method, *args) poo = <<-EOPOO.undent Unexpected method #{method} called on caveats in Cask #{@cask}. diff --git a/test/support/Casks/with-caveats.rb b/test/support/Casks/with-caveats.rb index 78d3605b4b..8ee34ec1d3 100644 --- a/test/support/Casks/with-caveats.rb +++ b/test/support/Casks/with-caveats.rb @@ -16,6 +16,9 @@ class WithCaveats < TestCask caveats do puts 'Custom text via puts followed by DSL-generated text:' manual_installer('Installer.app') + # since all known OS versions are specified, no output should be + # generated here during the test + os_versions_only('10.0', '10.1', '10.2', '10.3', '10.3', '10.5', '10.6', '10.7', '10.8', '10.9') end caveats do # since both valid arches are specified, no output should be