Skip to content

Commit 4948035

Browse files
committed
Refactor list-attributes-on-file dev script to Ruby
1 parent 862cb7f commit 4948035

2 files changed

Lines changed: 44 additions & 30 deletions

File tree

cmd/brew-list-url-attributes-on-file

Lines changed: 0 additions & 30 deletions
This file was deleted.

cmd/list-url-attributes-on-file.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
require "abstract_command"
5+
require "open3"
6+
7+
module Homebrew
8+
module Cmd
9+
class ListUrlAttributesOnFileCmd < AbstractCommand
10+
cmd_args do
11+
usage_banner <<~EOS
12+
`list-url-attributes-on-file` <file>
13+
14+
Given a downloaded file, extract possible sources from macOS extended
15+
attributes, which may be useful in a Cask url stanza.
16+
17+
Currently the only attribute examined is
18+
19+
com.apple.metadata:kMDItemWhereFroms
20+
21+
This attribute will typically be set if the file was downloaded via a
22+
browser, but not if the file was downloaded by a CLI utility such as
23+
curl.
24+
25+
See CONTRIBUTING.md for more information.
26+
EOS
27+
28+
named_args :file, max: 1
29+
30+
hide_from_man_page!
31+
end
32+
33+
sig { override.returns(T.any(T.nilable(String), T::Array[String])) }
34+
def run
35+
attribute = "com.apple.metadata:kMDItemWhereFroms"
36+
xattr, _, status = Open3.capture3("/usr/bin/xattr -p #{attribute} #{args.named.first}")
37+
38+
exit status.exitstatus.to_i unless status.success?
39+
40+
puts Plist.parse_xml(xattr, marshal: false) || xattr
41+
end
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)