Skip to content

Commit

Permalink
Update an installed plugin [#1 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Guidi committed May 16, 2008
1 parent 7bec00f commit 6ef3673
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Update an installed plugin [#1 state:resolved]

* Refactored Plugin and AbstractRepository to separate class responsabilities

* Remove a plugin from cache when uninstalled
Expand Down
28 changes: 26 additions & 2 deletions lib/sashimi/commands.rb
Expand Up @@ -26,6 +26,7 @@ def options

o.separator " install Install plugin from known URL."
o.separator " uninstall Uninstall plugin from local repository."
o.separator " update Update installed plugin(s)."

o.separator ""
o.separator "EXAMPLES"
Expand All @@ -35,6 +36,8 @@ def options
o.separator " #{@script_name} install git://github.com/jodosha/click-to-globalize.git\n"
o.separator " Uninstall a plugin:"
o.separator " #{@script_name} uninstall continuous_builder\n"
o.separator " Update a plugin:"
o.separator " #{@script_name} update click-to-globalize\n"
end
end

Expand All @@ -43,7 +46,7 @@ def parse!(args=ARGV)
options.parse!(general)

command = general.shift
if command =~ /^(install|uninstall)$/
if command =~ /^(install|uninstall|update)$/
command = Commands.const_get(command.capitalize).new(self)
command.parse!(sub)
else
Expand Down Expand Up @@ -109,5 +112,26 @@ def parse!(args)
end
end
end

class Update
def initialize(base_command)
@base_command = base_command
end

def options
OptionParser.new do |o|
o.set_summary_indent(' ')
o.banner = "Usage: #{@base_command.script_name} update PLUGIN"
o.define_head "Update an installed plugin."
end
end

def parse!(args)
options.parse!(args)
args.each do |name|
Plugin.new(name).update
end
end
end
end
end
end
7 changes: 6 additions & 1 deletion lib/sashimi/plugin.rb
Expand Up @@ -16,7 +16,12 @@ def install
def uninstall
repository.uninstall
end


# Update the plugin
def update
repository.update
end

def repository #:nodoc:
@repository ||= instantiate_repository
end
Expand Down
7 changes: 6 additions & 1 deletion lib/sashimi/repositories/git_repository.rb
Expand Up @@ -5,5 +5,10 @@ def install
system("git clone #{plugin.url}")
add_to_cache({plugin.guess_name => {'type' => 'git'}})
end

def update
change_dir_to_plugin_path
system('git pull')
end
end
end
end
5 changes: 5 additions & 0 deletions lib/sashimi/repositories/svn_repository.rb
Expand Up @@ -5,5 +5,10 @@ def install
system("svn co #{plugin.url} #{plugin.guess_name}")
add_to_cache({plugin.guess_name => {'type' => 'svn'}})
end

def update
change_dir_to_plugin_path
system("svn up")
end
end
end

0 comments on commit 6ef3673

Please sign in to comment.