Show changed examples on update [telemachus]
* Also move updater output into the class itself
This commit is contained in:
parent
da7854401d
commit
7768e59a50
@ -11,10 +11,17 @@ class RefreshBrew
|
|||||||
UPDATED_FORMULA = %r{^\s+#{formula_regexp}\s}
|
UPDATED_FORMULA = %r{^\s+#{formula_regexp}\s}
|
||||||
DELETED_FORMULA = %r{^\s+delete mode \d+ #{formula_regexp}$}
|
DELETED_FORMULA = %r{^\s+delete mode \d+ #{formula_regexp}$}
|
||||||
|
|
||||||
|
example_regexp = 'Library/Contributions/examples/([^.\s]+).*'
|
||||||
|
ADDED_EXAMPLE = %r{^\s+create mode \d+ #{example_regexp}$}
|
||||||
|
UPDATED_EXAMPLE = %r{^\s+#{example_regexp}}
|
||||||
|
DELETED_EXAMPLE = %r{^\s+delete mode \d+ #{example_regexp}$}
|
||||||
|
|
||||||
attr_reader :added_formulae, :updated_formulae, :deleted_formulae, :initial_revision
|
attr_reader :added_formulae, :updated_formulae, :deleted_formulae, :initial_revision
|
||||||
|
attr_reader :added_examples, :updated_examples, :deleted_examples
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@added_formulae, @updated_formulae, @deleted_formulae = [], [], []
|
@added_formulae, @updated_formulae, @deleted_formulae = [], [], []
|
||||||
|
@added_examples, @updated_examples, @deleted_examples = [], [], []
|
||||||
@initial_revision = self.current_revision
|
@initial_revision = self.current_revision
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -39,11 +46,20 @@ class RefreshBrew
|
|||||||
@deleted_formulae << $1
|
@deleted_formulae << $1
|
||||||
when UPDATED_FORMULA
|
when UPDATED_FORMULA
|
||||||
@updated_formulae << $1 unless @added_formulae.include?($1) or @deleted_formulae.include?($1)
|
@updated_formulae << $1 unless @added_formulae.include?($1) or @deleted_formulae.include?($1)
|
||||||
|
when ADDED_EXAMPLE
|
||||||
|
@added_examples << $1
|
||||||
|
when DELETED_EXAMPLE
|
||||||
|
@deleted_examples << $1
|
||||||
|
when UPDATED_EXAMPLE
|
||||||
|
@updated_examples << $1 unless @added_examples.include?($1) or @deleted_examples.include?($1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@added_formulae.sort!
|
@added_formulae.sort!
|
||||||
@updated_formulae.sort!
|
@updated_formulae.sort!
|
||||||
@deleted_formulae.sort!
|
@deleted_formulae.sort!
|
||||||
|
@added_examples.sort!
|
||||||
|
@updated_examples.sort!
|
||||||
|
@deleted_examples.sort!
|
||||||
|
|
||||||
output.strip != GIT_UP_TO_DATE
|
output.strip != GIT_UP_TO_DATE
|
||||||
end
|
end
|
||||||
@ -60,12 +76,62 @@ class RefreshBrew
|
|||||||
!@deleted_formulae.empty?
|
!@deleted_formulae.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pending_examples_changes?
|
||||||
|
!@updated_examples.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def pending_new_examples?
|
||||||
|
!@added_examples.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
def deleted_examples?
|
||||||
|
!@deleted_examples.empty?
|
||||||
|
end
|
||||||
|
|
||||||
def current_revision
|
def current_revision
|
||||||
HOMEBREW_REPOSITORY.cd { execute(REVISION_COMMAND).strip }
|
HOMEBREW_REPOSITORY.cd { execute(REVISION_COMMAND).strip }
|
||||||
rescue
|
rescue
|
||||||
'TAIL'
|
'TAIL'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def report
|
||||||
|
puts "Updated Homebrew from #{initial_revision[0,8]} to #{current_revision[0,8]}."
|
||||||
|
## New Formulae
|
||||||
|
if pending_new_formulae?
|
||||||
|
ohai "The following formulae are new:"
|
||||||
|
puts_columns added_formulae
|
||||||
|
end
|
||||||
|
## Deleted Formulae
|
||||||
|
if deleted_formulae?
|
||||||
|
ohai "The following formulae were removed:"
|
||||||
|
puts_columns deleted_formulae
|
||||||
|
end
|
||||||
|
## Updated Formulae
|
||||||
|
if pending_formulae_changes?
|
||||||
|
ohai "The following formulae were updated:"
|
||||||
|
puts_columns updated_formulae
|
||||||
|
else
|
||||||
|
puts "No formulae were updated."
|
||||||
|
end
|
||||||
|
## New examples
|
||||||
|
if pending_new_examples?
|
||||||
|
ohai "The following external commands are new:"
|
||||||
|
puts_columns added_examples
|
||||||
|
end
|
||||||
|
## Deleted examples
|
||||||
|
if deleted_examples?
|
||||||
|
ohai "The following external commands were removed:"
|
||||||
|
puts_columns deleted_examples
|
||||||
|
end
|
||||||
|
## Updated Formulae
|
||||||
|
if pending_examples_changes?
|
||||||
|
ohai "The following external commands were updated:"
|
||||||
|
puts_columns updated_examples
|
||||||
|
else
|
||||||
|
puts "No external commands were updated."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def execute(cmd)
|
def execute(cmd)
|
||||||
|
|||||||
19
bin/brew
19
bin/brew
@ -172,24 +172,7 @@ begin
|
|||||||
unless updater.update_from_masterbrew!
|
unless updater.update_from_masterbrew!
|
||||||
puts "Already up-to-date."
|
puts "Already up-to-date."
|
||||||
else
|
else
|
||||||
puts "Updated Homebrew from #{updater.initial_revision[0,8]} to #{updater.current_revision[0,8]}."
|
updater.report
|
||||||
## New Formulae
|
|
||||||
if updater.pending_new_formulae?
|
|
||||||
ohai "The following formulae are new:"
|
|
||||||
puts_columns updater.added_formulae
|
|
||||||
end
|
|
||||||
## Deleted Formulae
|
|
||||||
if updater.deleted_formulae?
|
|
||||||
ohai "The following formulae were removed:"
|
|
||||||
puts_columns updater.deleted_formulae
|
|
||||||
end
|
|
||||||
## Updated Formulae
|
|
||||||
if updater.pending_formulae_changes?
|
|
||||||
ohai "The following formulae were updated:"
|
|
||||||
puts_columns updater.updated_formulae
|
|
||||||
else
|
|
||||||
puts "No formulae were updated."
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
when 'ln', 'link'
|
when 'ln', 'link'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user