Merge pull request #1224 from reitermarkus/refactor-extensions
Refactor Cask’s extensions.
This commit is contained in:
commit
a7a2aef803
@ -1,7 +1,6 @@
|
|||||||
module Hbc; end
|
module Hbc; end
|
||||||
|
|
||||||
require "hardware"
|
require "hardware"
|
||||||
require "hbc/extend"
|
|
||||||
require "hbc/artifact"
|
require "hbc/artifact"
|
||||||
require "hbc/audit"
|
require "hbc/audit"
|
||||||
require "hbc/auditor"
|
require "hbc/auditor"
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
require "hbc/artifact/moved"
|
require "hbc/artifact/moved"
|
||||||
|
|
||||||
|
require "hbc/utils/hash_validator"
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
module Artifact
|
module Artifact
|
||||||
class Artifact < Moved
|
class Artifact < Moved
|
||||||
@ -16,7 +18,7 @@ module Hbc
|
|||||||
raise CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil?
|
raise CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil?
|
||||||
@source = @cask.staged_path.join(source_string)
|
@source = @cask.staged_path.join(source_string)
|
||||||
raise CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash)
|
raise CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash)
|
||||||
target_hash.assert_valid_keys(:target)
|
target_hash.extend(HashValidator).assert_valid_keys(:target)
|
||||||
@target = Pathname.new(target_hash[:target])
|
@target = Pathname.new(target_hash[:target])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
require "hbc/artifact/base"
|
require "hbc/artifact/base"
|
||||||
|
|
||||||
|
require "hbc/utils/hash_validator"
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
module Artifact
|
module Artifact
|
||||||
class Pkg < Base
|
class Pkg < Base
|
||||||
@ -14,7 +16,7 @@ module Hbc
|
|||||||
@pkg_install_opts = pkg_description.shift
|
@pkg_install_opts = pkg_description.shift
|
||||||
begin
|
begin
|
||||||
if @pkg_install_opts.respond_to?(:keys)
|
if @pkg_install_opts.respond_to?(:keys)
|
||||||
@pkg_install_opts.assert_valid_keys(:allow_untrusted)
|
@pkg_install_opts.extend(HashValidator).assert_valid_keys(:allow_untrusted)
|
||||||
elsif @pkg_install_opts
|
elsif @pkg_install_opts
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
require "hbc/artifact/base"
|
require "hbc/artifact/base"
|
||||||
|
|
||||||
|
require "hbc/utils/hash_validator"
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
module Artifact
|
module Artifact
|
||||||
class Relocated < Base
|
class Relocated < Base
|
||||||
@ -46,7 +48,7 @@ module Hbc
|
|||||||
@source = @cask.staged_path.join(source_string)
|
@source = @cask.staged_path.join(source_string)
|
||||||
if target_hash
|
if target_hash
|
||||||
raise CaskInvalidError unless target_hash.respond_to?(:keys)
|
raise CaskInvalidError unless target_hash.respond_to?(:keys)
|
||||||
target_hash.assert_valid_keys(:target)
|
target_hash.extend(HashValidator).assert_valid_keys(:target)
|
||||||
@target = Hbc.send(self.class.artifact_dirmethod).join(target_hash[:target])
|
@target = Hbc.send(self.class.artifact_dirmethod).join(target_hash[:target])
|
||||||
else
|
else
|
||||||
@target = Hbc.send(self.class.artifact_dirmethod).join(source.basename)
|
@target = Hbc.send(self.class.artifact_dirmethod).join(source.basename)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require "optparse"
|
require "optparse"
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
|
|
||||||
|
require "extend/optparse"
|
||||||
|
|
||||||
require "hbc/cli/base"
|
require "hbc/cli/base"
|
||||||
require "hbc/cli/audit"
|
require "hbc/cli/audit"
|
||||||
require "hbc/cli/cat"
|
require "hbc/cli/cat"
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# monkeypatching
|
|
||||||
require "hbc/extend/hash"
|
|
||||||
require "hbc/extend/io"
|
|
||||||
require "hbc/extend/optparse"
|
|
||||||
require "extend/pathname"
|
|
||||||
require "hbc/extend/string"
|
|
@ -1,5 +0,0 @@
|
|||||||
class String
|
|
||||||
def undent
|
|
||||||
gsub(%r{^.{#{(slice(%r{^ +}) || '').length}}}, "")
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,6 +1,10 @@
|
|||||||
require "open3"
|
require "open3"
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
|
|
||||||
|
require "extend/io"
|
||||||
|
|
||||||
|
require "hbc/utils/hash_validator"
|
||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
class SystemCommand
|
class SystemCommand
|
||||||
attr_reader :command
|
attr_reader :command
|
||||||
@ -43,7 +47,8 @@ module Hbc
|
|||||||
attr_reader :executable, :options, :processed_output, :processed_status
|
attr_reader :executable, :options, :processed_output, :processed_status
|
||||||
|
|
||||||
def process_options!
|
def process_options!
|
||||||
options.assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo, :bsexec
|
options.extend(HashValidator)
|
||||||
|
.assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo, :bsexec
|
||||||
sudo_prefix = %w[/usr/bin/sudo -E --]
|
sudo_prefix = %w[/usr/bin/sudo -E --]
|
||||||
bsexec_prefix = ["/bin/launchctl", "bsexec", options[:bsexec] == :startup ? "/" : options[:bsexec]]
|
bsexec_prefix = ["/bin/launchctl", "bsexec", options[:bsexec] == :startup ? "/" : options[:bsexec]]
|
||||||
@command = [executable]
|
@command = [executable]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
class Hash
|
module HashValidator
|
||||||
def assert_valid_keys(*valid_keys)
|
def assert_valid_keys(*valid_keys)
|
||||||
unknown_keys = keys - valid_keys
|
unknown_keys = keys - valid_keys
|
||||||
return if unknown_keys.empty?
|
return if unknown_keys.empty?
|
Loading…
x
Reference in New Issue
Block a user