Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Expose the 'delete' we operation via the command line.

Closes #10
  • Loading branch information...
commit 68e97fcc62f24058d4d0d71547c1ed1200ebb4e9 1 parent 9de41be
@copiousfreetime authored
View
8 bin/stickler
@@ -3,7 +3,7 @@
require 'stickler'
require 'stickler/client'
-SUB_COMMANDS = %w[ push yank mirror config list ].sort
+SUB_COMMANDS = %w[ push yank mirror config list delete ].sort
exec_name = File.basename( $0 )
#----------------------------------------------------------------------
@@ -24,6 +24,7 @@ Stickler server interaction
#{exec_name} mirror --help
#{exec_name} config --server http://stickler.example.com --upstream http://rubygems.org/
#{exec_name} list --server http://stickler.example.com
+ #{exec_name} delete my_gem --gem-version 1.2.3 --server #http://stickler.example.com/
Options:
_
@@ -35,7 +36,8 @@ end
# sub command processing
#----------------------------------------------------------------------
cmd = ARGV.shift
-Trollop::die "unknown sub command #{cmd.inspect}" unless SUB_COMMANDS.include?( cmd )
+Trollop::die "No sub command given" unless cmd
+Trollop::die "Unknown sub command #{cmd.inspect}" unless SUB_COMMANDS.include?( cmd )
case cmd
@@ -43,6 +45,8 @@ when "push"
::Stickler::Client::Push.new( ARGV ).run
when "yank"
::Stickler::Client::Yank.new( ARGV ).run
+when "delete"
+ ::Stickler::Client::Delete.new( ARGV ).run
when "mirror"
::Stickler::Client::Mirror.new( ARGV ).run
when "config"
View
1  lib/stickler/client.rb
@@ -45,6 +45,7 @@ def remote_repo_for( opts )
require 'stickler/client/push'
require 'stickler/client/yank'
+require 'stickler/client/delete'
require 'stickler/client/mirror'
require 'stickler/client/config'
require 'stickler/client/list'
View
50 lib/stickler/client/delete.rb
@@ -0,0 +1,50 @@
+module Stickler
+ class Client
+ class Delete < Stickler::Client
+ def self.banner
+<<-_
+Completely Remove a gem from the gemserver's index.
+
+Usage: stickler delete [options] --gem-version x.y.z gem
+
+ Options:
+_
+ end
+
+ def parser
+ unless @parser then
+ @parser = super
+ @parser.opt( :gem_version, "The version of the gem to delete (required)", :type => :string, :required => true )
+ @parser.opt( :platform, "The platform of the gem to delete ", :type => :string, :default => ::Gem::Platform::RUBY )
+ end
+ return @parser
+ end
+
+ def parse( argv )
+ gem_name = nil
+ opts = super( argv ) do |p|
+ raise Trollop::CommandlineError, "At least one gem is required to delete" if p.leftovers.empty?
+ gem_name = p.leftovers.shift
+ end
+ opts[:gem_name] = gem_name
+ return opts
+ end
+
+ def run
+ opts = parse( self.argv )
+ repo = remote_repo_for( opts )
+ spec = Stickler::SpecLite.new( opts[:gem_name], opts[:gem_version], opts[:platform] )
+
+ $stdout.write "Deleting gem #{spec.full_name} from #{repo.uri} : "
+ $stdout.flush
+ if spec = repo.delete( spec ) then
+ $stdout.puts "OK"
+ else
+ $stdout.puts "FAILURE"
+ end
+ rescue Stickler::Repository::Error => e
+ $stdout.puts "ERROR: #{e.message}"
+ end
+ end
+ end
+end
View
4 lib/stickler/middleware/gemcutter.rb
@@ -54,8 +54,8 @@ def initialize( app = nil, options = {} )
end
# direct delete
- delete %r{\A/gems/((.*?)-([0-9.]+)(-.*?)?)\.gem\Z} do
- full_name, name, version, platform = *params[:captures]
+ delete %r{\A/gems/#{NAME_VERSION_PLATFORM_REGEX}\.gem\Z} do
+ name, version, platform = *params[:captures]
spec = Stickler::SpecLite.new( name, version, platform )
@repo.delete( spec )
logger.info( "Deleted #{spec.full_name}" )
Please sign in to comment.
Something went wrong with that request. Please try again.