librelist archives

« back to archive

Refactor

Refactor

From:
Max Howell
Date:
2010-11-27 @ 13:20
			We have a big refactor. Please review it.In summary: some cleanup but 
mostly moving every command into its own file. I'm pretty happy with the 
results.https://github.com/mxcl/homebrew/tree/refactorAt this point we are
mostly looking for glaring ommissions, possibly breakage. Please keep 
discussion of how rubbish the whole concept is (or whatever) on the list. 
Please comment line wise at Github.Thanks and kisses,Max

Re: [homebrew] Refactor

From:
Benoit Daloze
Date:
2010-11-27 @ 15:09
On 27 November 2010 14:20, Max Howell <max@methylblue.com> wrote:
> We have a big refactor. Please review it.
> In summary: some cleanup but mostly moving every command into its own file.
> I'm pretty happy with the results.
> https://github.com/mxcl/homebrew/tree/refactor
> At this point we are mostly looking for glaring ommissions, possibly
> breakage. Please keep discussion of how rubbish the whole concept is (or
> whatever) on the list. Please comment line wise at Github.
> Thanks and kisses,
> Max

This seems to be a very good change.

As an external command writer, I would like to be able to call brew
commands with a nice API. (instead of using the bad system('brew
...'))

I think a brew method would fit well.
bin/brew would then mostly be brew(ARGV) with of course some checks
for the command, and maybe turn --options into flags (like :cache).

My workaround was to mutate ARGV, but I feel it not so safe.
However, I think the ARGV.option? is really nice, and this idea would
make it looks more like args.include? :option which is not as nice.
Except, if args is a subclass with the same properties as ARGV.
The flow would be more natural, by passing arguments, rather than
supposing ARGV is kept the same trough methods.
In code:

# in the external command
require 'brew'
brew(:command, args)

# in bin/brew
brew(:command, ARGV)

# in a command
def command(*args)
  if args.option?
    ...

# brew
def brew(command, args)
  args = Args.new(args) # or extend a Args module
  send(command, args) # with extra checks
end

What do you think?