-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add language method to OS::Mac
.
#897
Conversation
OS:Mac
.OS::Mac
.
6bf9266
to
9359299
Compare
@@ -41,6 +41,10 @@ def cat | |||
version.to_sym | |||
end | |||
|
|||
def language | |||
@language ||= `defaults read .GlobalPreferences AppleLanguages`.delete(" \n\"()").sub(%r{,.*}, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use Utils.popen_read
instead here? Backticks are inconsistent with the rest of the file here... and kind of gross to look at 😄.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is it worth using gsub
? I'd also favour //
regexes unless they contain /
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean gsub
instead of .delete.sub
or instead of only .sub
?
Example output is:
(
"de-AT",
"en-GB",
en
)
So delete
gives you a nice CSV-like string: "de-AT,en-GB,en"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving as is because I don't think having a complex regex here is worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels weird on hindsight to return a comma-separated string. .delete("()\"\n ").split(",")
seems to do what you want and return an array.
Feels a little weird for this to be on the MacOS class but I don't have strong feelings either way if there's no other logical place. |
Where else would you put the OS language, if not in the |
👍 |
9359299
to
018ee5a
Compare
@@ -41,6 +41,10 @@ def cat | |||
version.to_sym | |||
end | |||
|
|||
def language | |||
@language ||= Utils.popen_read('defaults', 'read', '.GlobalPreferences', 'AppleLanguages').delete(" \n\"()").sub(/,.*/, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes is probably a Rubocop violation given Homebrew's Rubocop config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of RuboCop, when was the last time someone actually ran it? Seems there are hundreds of violations.
Edit: I ran it in Library/Homebrew
instead of Library
. It seems to be broken anyway because of the dependency on rubocop-cask
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mass-fixed core code pre-separation, so a while ago. There is stuff Rubocop skips over automatically fixing though, as well as us having changed various Rubocop rules between then & now.
e414e63
to
60a4060
Compare
Ok, should be good to go now. |
60a4060
to
0243e1f
Compare
Merging now in order for Homebrew/homebrew-cask#24343 and Homebrew/homebrew-cask-versions#2558 to hopefully go green. |
@reitermarkus Did you miss this:
I'd have preferred if you disagreed that it was discussed rather than merged? |
It doesn't return a comma-separated string. The |
Ok. Why does this only care about the first value? That feels relatively opinionated for something that's a OS wrapper around a method? Regardless: this is discussion we should really be having before this was merged. |
Yes, sorry, I missed that comment. For context, please take a look at https://github.com/caskroom/homebrew-cask/pull/24343/files#diff-d7a1b27ed779bc1601aadf2a1c3652f7R12 on how this is supposed to be used. Alternatively, to make this less opinionated, we could make |
@reitermarkus No worries. 👍 to having |
brew tests
with your changes locally?This adds a
language
method to theMacOS
module, to be used in casks, such as Homebrew/homebrew-cask#24343.cc @Homebrew/cask