add command 'cask outdated'#2309
Conversation
There was a problem hiding this comment.
It does happen occasionally.
You can’t compare “size”, because versions are non-standard, for us. A version can just as well be a number or an intelligible string. The only comparison that can be made is “is it different?”. |
|
I think sortable versions might also be a prerequisite for this making any sense. |
|
You both are right regarding the version comparison. I had semantic versioning in mind but I overlooked that, as strings, "10" is smaller than "9". And semantic versioning is a foolish assumption in this case, anyway. Simplified the version comparison in a new commit. |
There was a problem hiding this comment.
Are you sure? It says: Error: undefined method `verbose?' for Hbc::CLI::Outdated:Class
There was a problem hiding this comment.
Ah, then it's CLI.verbose?, I thought it would use the CLI namespace.
There was a problem hiding this comment.
#select is the function I was looking for (but it seems I was too lazy to read the complete list of Array methods and I concluded too early). Thank you!
There was a problem hiding this comment.
Let's not cache this. At the moment we are only using it only once anyways, but even if we were to use it multiple times, something will probably have changed between these calls.
There was a problem hiding this comment.
#outdated? and outdated_versions are both called when --verbose. This is why the information is cached (versions is expensive).
Is it ok to (drop caching and the #outdated_versions method and) let #outdated? return a boolean and the list of outdated versions?
There was a problem hiding this comment.
This is the output format used by brew outdated and it is also the one suggested in Homebrew/homebrew-cask#29301
There was a problem hiding this comment.
I understood the reasons about using != to compare the versions and I changed the code.
Please remark the puts in front of that line. It is not a version comparison, "<" is part of the text that is displayed to the user:
$ brew cask outdated
cyberduck (5.3.7.23440, 5.3.8.23611) < 5.3.9.23624
virtualbox (5.1.14-112924) < 5.1.16-113841
virtualbox-extension-pack (5.1.14-112924) < 5.1.16-113841
There was a problem hiding this comment.
Yes, that is exactly the reason. Displaying < when we are only comparing with != doesn't make sense.
There was a problem hiding this comment.
I got your point now. But I still wonder what kind of magic allows brew outdated compare the Formula versions using <.
There was a problem hiding this comment.
This is because Formulae use the comparable PkgVersion class, and Hbc::DSL::Version is a subclass of String, so it only performs a String comparison.
0814bd1 to
6049980
Compare
There was a problem hiding this comment.
Make this if version == current.
There was a problem hiding this comment.
This should be:
if greedy
return versions if version.latest?
else
return [] if auto_updates
endOtherwise, when I have the :latest version installed, but there is an updated cask with version 1.0.0, it will not show up as outdated.
There was a problem hiding this comment.
This must be removed after changing the above to if greedy.
There was a problem hiding this comment.
No need for the if here, version != v is enough.
There was a problem hiding this comment.
Or even select(&version.method(:!=)).
7994151 to
6df8290
Compare
There was a problem hiding this comment.
Ok, I changed my mind, I think select { |v| version != v } is clearer.
There was a problem hiding this comment.
It is clearer, indeed.
There was a problem hiding this comment.
Make this expect(c).to be_outdated everywhere.
There was a problem hiding this comment.
It's expect(c).to_not be_outdated. Got it.
There was a problem hiding this comment.
Right, but use .not_to instead of .to_not.
There was a problem hiding this comment.
Instead of this, use allow(Hbc::CLI).to receive(:verbose?).and_return(true).
There was a problem hiding this comment.
This eliminates the need to reset CLI.verbose in after, isn't it?
There was a problem hiding this comment.
Define these like
let(:basic_cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }above the before block.
There was a problem hiding this comment.
I think these are automatically removed after each test.
|
Heya, I'm disappointed that we ended up duplicating effort, but this looks much neater than my PR (#2250). I also learnt a bunch of ruby and rspec reading your version. Thanks :) |
There was a problem hiding this comment.
No need to test this, since this is basically the same for every command and I think this is already tested elsewhere.
There was a problem hiding this comment.
@reitermarkus you want to spoil my perfect code coverage ;-)
I agree it is not needed; I just exercised the things you taught me in your previous review (.not_to, mocking method calls) and I enjoyed using them. I removed the test now and rebased the branch.
There was a problem hiding this comment.
@reitermarkus you want to spoil my perfect code coverage ;-)
Fixed that for you, by adding a test for the help methods. 😄
|
@joshka Thank you for your appreciation. I'm sorry my PR rendered your work useless, it was not my intention. You can still implement |
brew testswith your changes locally?Disclaimer for the unchecked item
A couple of weeks ago I was missing the
brew cask outdatedcommand. I checked the Issues and PRs on the Homebrew/brew repo and I couldn't find anything related so I decided to give it a try.When I was ready to make a pull request I discovered PR #2250 was already created two days before and I learned about issue Homebrew/homebrew-cask#29301. I went back to coding, implemented the
--greedyoption too and now I have a complete PR for thecask outdatedfeature.How it works:
When the
--greedyoptions is not present in the command line, a Cask that hasauto_updates trueorversion 'latest'is ignored, as required.When
--greedyis present, the value ofauto_updatesis ignored and the Cask is processed as explained below; the casks that haveversion 'latest'are always displayed as outdated.The version of the Cask from tap is compared against the currently installed version of the application (
versions.last). The Cask is outdated if the currently installed version is different than the version from the tap. In this case, all the local versions of the application are compared to the tap version and all that are different are reported as "outdated".If the current installed version is the same as the tap version, the Cask is not reported as outdated, even if there are other (different) local versions.
Output formatting
The format of the command is the same as the output of
brew outdated, including the processing of--verboseand--quietcommand line options.Other points of interest
The new functionality is accompanied by tests. The documentation (the
manpage) was updated.