argv: move formulae to cli/args#6433
Conversation
There was a problem hiding this comment.
@resolved_formulae ||= (downcased_unique_named - casks).map do |name| and remove TODO
There was a problem hiding this comment.
I've already tried exactly this but it was breaking a lot of tests. Let me try again.
There was a problem hiding this comment.
You may need to add a Homebrew.args.reset or similar which will reset the instance variables and have it in https://github.com/Homebrew/brew/blob/master/Library/Homebrew/test/spec_helper.rb#L135-L208
In general there's some ARGV stuff there that may need similar code for Homebrew.args
There was a problem hiding this comment.
I think we've hit a cyclic dependency here.
formula_options method is used to allow extra arguments for formulae see - deps.rb#L55 and install.rb#L90 but formula_options itself needs to know what is passed on command line to define what options can be allowed on command line!
There was a problem hiding this comment.
In that case you might want to allow e.g. ARGV to be passed in in some circumstances for initialisation so it's not operating on itself? Would that work?
There was a problem hiding this comment.
Yeah, if we limit the usage of ARGV to this one method we could make this work.
There was a problem hiding this comment.
I would suggest it's passed in as an argument (a default one if necessary) to make testing easier and just treated as an Array. The issue we're trying to address isn't so much the use of ARGV but removing our patches on ARGV.
34b8fe8 to
2cd58ca
Compare
633383b to
2e3a7dc
Compare
2e3a7dc to
6c0b87c
Compare
|
@MikeMcQuaid https://github.com/Homebrew/brew/runs/276504778#step:5:373 |
|
@GauthamGoli Are you stuck/blocked on this now? If so, can take a look and try to fix the tests. If it's not being passed but showing up that sounds like something being cached between tests that needs reset. |
|
|
@GauthamGoli Maybe this needs rebased on |
6c0b87c to
01e9682
Compare
|
Tests fail even after rebase. |
There was a problem hiding this comment.
It looks like this is not being detected properly.
Had a look: the issue isn't that |
01e9682 to
a09f246
Compare
|
Got it! Thanks. Its the chicken egg problem of |
|
Tests pass now. |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
A few minor questions but looks really good, nice work @GauthamGoli!
There was a problem hiding this comment.
Think it would be good to handle both the above at once and perhaps even return @args, @args_parsed, @parser all from this method to be able to make these attr_reader instead of attr_accessor.
There was a problem hiding this comment.
I'm not sure I understand this completely. Could you please add in an example code snippet here. Thanks!
There was a problem hiding this comment.
| Homebrew.args.args_parsed = @args_parsed |
There was a problem hiding this comment.
Should/could this logic live inside HEAD??
There was a problem hiding this comment.
HEAD? is one of the keys in OpenStruct, so I don't think so it possible.
We could extract this logic out to another private method named HEAD
There was a problem hiding this comment.
Yeh, a private method for this sounds good 👍
|
@GauthamGoli @MikeMcQuaid So I guess I didn't notice that this PR moved the kegs method to args.rb when I started on #6622, should I just close that one and suggest changes here for the files that use ARGV.kegs? |
|
@zachauten #6622 need not be closed, after this PR is merged, you can rebase on master. |
There was a problem hiding this comment.
| @args_parsed = true | |
| @args.args_parsed = @args_parsed = true |
There was a problem hiding this comment.
| Homebrew.args.args_parsed = @args_parsed |
There was a problem hiding this comment.
| attr_accessor :processed_options, :args_parsed | |
| attr_reader :processed_options, :args_parsed |
There was a problem hiding this comment.
https://github.com/Homebrew/brew/pull/6433/files#diff-e0e03670c451d934ae1d79adfff63cacR144
cannot be executed with only attr_reader
There was a problem hiding this comment.
Ok but I think it would be better to have a custom method that allows them to only be set once and then be frozen/not allow future changes to be made rather than using attr_accessor
There was a problem hiding this comment.
@MikeMcQuaid What do you think about this approach?
a09f246 to
224a9e3
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Looking good! A couple of final tiny things then good to merge.
Another thing I noticed is that it'd be nice to have https://github.com/Homebrew/brew/blob/86607314eabc7ed11a1860c3f88c517d83f3d113/Library/Homebrew/cli/parser.rb#L143 (@args_parsed) moved until as late as possible in the method just so it isn't set prematurely if something fails.
There was a problem hiding this comment.
I like this a lot more 👍. How about making it freeze_processed_options!(processed_options) to make it clearer it can only be called once?
There was a problem hiding this comment.
| @processed_options.concat(processed_options) | |
| @processed_options += processed_options |
There was a problem hiding this comment.
I'd suggest putting this last just to avoid it being set if e.g. the freeze fails.
8660731 to
2b95755
Compare
|
Thanks again for more great work @GauthamGoli 🎉 |
|
We need to watch this closely for a few days for any bugs. I will be watching the issues 👍 |
brew stylewith your changes locally?brew testswith your changes locally?#5730
Please do not merge until #6411 gets merged.