Add type signatures for Cask::Staged.
This commit is contained in:
parent
64a0e9a721
commit
66bf1314a1
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "utils/user"
|
||||
@ -8,25 +8,35 @@ module Cask
|
||||
#
|
||||
# @api private
|
||||
module Staged
|
||||
extend T::Sig
|
||||
|
||||
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
|
||||
# rubocop:disable Style/MutableConstant
|
||||
Paths = T.type_alias { T.any(String, Pathname, T::Array[T.any(String, Pathname)]) }
|
||||
# rubocop:enable Style/MutableConstant
|
||||
|
||||
sig { params(paths: Paths, permissions_str: String).void }
|
||||
def set_permissions(paths, permissions_str)
|
||||
full_paths = remove_nonexistent(paths)
|
||||
return if full_paths.empty?
|
||||
|
||||
@command.run!("/bin/chmod", args: ["-R", "--", permissions_str] + full_paths,
|
||||
@command.run!("/bin/chmod", args: ["-R", "--", permissions_str, *full_paths],
|
||||
sudo: false)
|
||||
end
|
||||
|
||||
def set_ownership(paths, user: User.current, group: "staff")
|
||||
sig { params(paths: Paths, user: T.any(String, User), group: String).void }
|
||||
def set_ownership(paths, user: T.must(User.current), group: "staff")
|
||||
full_paths = remove_nonexistent(paths)
|
||||
return if full_paths.empty?
|
||||
|
||||
ohai "Changing ownership of paths required by #{@cask}; your password may be necessary"
|
||||
@command.run!("/usr/sbin/chown", args: ["-R", "--", "#{user}:#{group}"] + full_paths,
|
||||
@command.run!("/usr/sbin/chown", args: ["-R", "--", "#{user}:#{group}", *full_paths],
|
||||
sudo: true)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
sig { params(paths: Paths).returns(T::Array[Pathname]) }
|
||||
def remove_nonexistent(paths)
|
||||
Array(paths).map { |p| Pathname(p).expand_path }.select(&:exist?)
|
||||
end
|
||||
|
||||
7
Library/Homebrew/cask/staged.rbi
Normal file
7
Library/Homebrew/cask/staged.rbi
Normal file
@ -0,0 +1,7 @@
|
||||
# typed: strict
|
||||
|
||||
module Cask
|
||||
module Staged
|
||||
include Kernel
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user