bundle/mac_app_store_dumper: typed: strict
This commit is contained in:
parent
1a45660194
commit
579c31f001
@ -1,4 +1,4 @@
|
|||||||
# typed: true # rubocop:todo Sorbet/StrictSigil
|
# typed: strict
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "json"
|
require "json"
|
||||||
@ -6,11 +6,14 @@ require "json"
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
module Bundle
|
module Bundle
|
||||||
module MacAppStoreDumper
|
module MacAppStoreDumper
|
||||||
|
sig { void }
|
||||||
def self.reset!
|
def self.reset!
|
||||||
@apps = nil
|
@apps = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[[String, String]]) }
|
||||||
def self.apps
|
def self.apps
|
||||||
|
@apps ||= T.let(nil, T.nilable(T::Array[[String, String]]))
|
||||||
@apps ||= if Bundle.mas_installed?
|
@apps ||= if Bundle.mas_installed?
|
||||||
`mas list 2>/dev/null`.split("\n").map do |app|
|
`mas list 2>/dev/null`.split("\n").map do |app|
|
||||||
app_details = app.match(/\A(?<id>\d+)\s+(?<name>.*?)\s+\((?<version>[\d.]*)\)\Z/)
|
app_details = app.match(/\A(?<id>\d+)\s+(?<name>.*?)\s+\((?<version>[\d.]*)\)\Z/)
|
||||||
@ -19,7 +22,7 @@ module Homebrew
|
|||||||
# Strip unprintable characters
|
# Strip unprintable characters
|
||||||
if app_details
|
if app_details
|
||||||
name = T.must(app_details[:name])
|
name = T.must(app_details[:name])
|
||||||
[app_details[:id], name.gsub(/[[:cntrl:]]|[\p{C}]/, "")]
|
[T.must(app_details[:id]), name.gsub(/[[:cntrl:]]|[\p{C}]/, "")]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -27,10 +30,12 @@ module Homebrew
|
|||||||
end.compact
|
end.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(T::Array[Integer]) }
|
||||||
def self.app_ids
|
def self.app_ids
|
||||||
apps.map { |id, _| id.to_i }
|
apps.map { |id, _| id.to_i }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
def self.dump
|
def self.dump
|
||||||
apps.sort_by { |_, name| name.downcase }.map { |id, name| "mas \"#{name}\", id: #{id}" }.join("\n")
|
apps.sort_by { |_, name| name.downcase }.map { |id, name| "mas \"#{name}\", id: #{id}" }.join("\n")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user