lib/gemfury/command/app.rb in gemfury-0.3.2 vs lib/gemfury/command/app.rb in gemfury-0.4.0.beta1
- old
+ new
@@ -1,8 +1,11 @@
class Gemfury::Command::App < Thor
include Gemfury::Command::Authorization
+ # Impersonation
+ class_option :as, :desc => 'Access an account other than your own'
+
map "-v" => :version
desc "version" ,"Show Gemfury version", :hide => true
def version
shell.say Gemfury::VERSION
end
@@ -33,11 +36,11 @@
with_checks_and_rescues do
gems = client.list
shell.say "\n*** GEMFURY GEMS ***\n\n"
gems.each do |g|
desc, version = g['name'], g.path('latest_version.version')
- desc << " (#{version})" if version
+ desc << " (#{version ? version : 'beta'})"
shell.say desc
end
end
end
@@ -70,15 +73,52 @@
wipe_credentials!
shell.say "You have been logged out"
end
end
+ ### COLLABORATION MANAGEMENT ###
+ map "sharing:add" => 'sharing_add'
+ map "sharing:remove" => 'sharing_remove'
+
+ desc "sharing", "List collaborators"
+ def sharing
+ with_checks_and_rescues do
+ me = client.account_info['username']
+ collaborators = client.list_collaborators
+ if collaborators.empty?
+ shell.say "You (#{me}) are the only collaborator", :green
+ else
+ shell.say %Q(\n*** Collaborators for "#{me}" ***\n), :green
+ usernames = [me] + collaborators.map { |c| c['username'] }
+ shell.say usernames.join("\n")
+ end
+ shell.say "\n"
+ end
+ end
+
+ desc "sharing:add USERNAME", "Add a collaborator"
+ def sharing_add(username)
+ with_checks_and_rescues do
+ client.add_collaborator(username)
+ shell.say "Added #{username} as a collaborator"
+ end
+ end
+
+ desc "sharing:remove USERNAME", "Remove a collaborator"
+ def sharing_remove(username)
+ with_checks_and_rescues do
+ client.remove_collaborator(username)
+ shell.say "Removed #{username} as a collaborator"
+ end
+ end
+
private
def client
- options = {}
- options[:user_api_key] = @user_api_key if @user_api_key
- Gemfury::Client.new(options)
+ opts = {}
+ opts[:user_api_key] = @user_api_key if @user_api_key
+ opts[:account] = options[:as] if options[:as]
+ Gemfury::Client.new(opts)
end
def with_checks_and_rescues(&block)
with_authorization(&block)
rescue Gemfury::InvalidGemVersion => e
@@ -86,9 +126,11 @@
if shell.yes? "Would you like to update this gem now? [yN]"
exec("gem update gemfury")
else
shell.say %q(No problem. You can also run "gem update gemfury")
end
+ rescue Gemfury::Forbidden => e
+ shell.say "Oops! You're not allowed to access this", :red
rescue Gemfury::NotFound => e
shell.say "Oops! Doesn't look like this exists", :red
rescue Exception => e
shell.say "Oops! Something went wrong. Looking into it ASAP!", :red
end
\ No newline at end of file