Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
collab command
Browse files Browse the repository at this point in the history
  • Loading branch information
justinko committed Nov 13, 2010
1 parent 5346d46 commit c8bf3f3
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 63 deletions.
28 changes: 14 additions & 14 deletions features/help.feature
Expand Up @@ -4,26 +4,26 @@ Feature: Help
The `relish help` command displays all available commands
along with a description of each.

The `relish help:<command>` option will display help text
for that particular command.

Scenario: View all available commands with the help command
When I successfully run "relish help"
Then the output should contain exactly:
"""
=== Available Commands
help # show this usage
config # display the contents of your options file
config:show # display the contents of your options file
config:add --<option> <value> # add a configuration option to your options file
projects # list your projects
projects:list # list your projects
projects:add <org_or_user_handle>/<project_handle> # add a project
# append :private to make the project private
# example: relish projects:add rspec/rspec-core:private
projects:remove <org_or_user_handle>/<project_handle> # remove a project
push # push features to relishapp.com
help # show this usage
config # display the contents of your options file
config:add --<option> <value> # add a configuration option to your options file
projects # list your projects
projects:add <org_or_user_handle>/<project_handle> # add a project
# append :private to make the project private
# example: relish projects:add rspec/rspec-core:private
projects:remove <org_or_user_handle>/<project_handle> # remove a project
push # push features to relishapp.com
collab # list the collaborators for a project
collab:add <org_or_user_handle>/<project_handle>:<collaborator_handle_or_email> # add a collaborator to a project
# example: relish collab:add rspec/rspec-core:justin
collab:remove <org_or_user_handle>/<project_handle>:<collaborator_handle_or_email> # remove a collaborator from a project
# example: relish collab:remove rspec/rspec-core:justin
"""

Expand Down
5 changes: 3 additions & 2 deletions lib/relish/command.rb
@@ -1,10 +1,11 @@
require 'relish'
require 'relish/helpers'
require 'relish/commands/base'
require 'relish/commands/push'
require 'relish/commands/collab'
require 'relish/commands/config'
require 'relish/commands/projects'
require 'relish/commands/help'
require 'relish/commands/projects'
require 'relish/commands/push'

module Relish
module Command
Expand Down
9 changes: 9 additions & 0 deletions lib/relish/commands/base.rb
@@ -1,4 +1,5 @@
require 'yaml'
require 'json'
require 'relish/ui'
require 'relish/options_file'
require 'relish/commands/dsl'
Expand Down Expand Up @@ -81,6 +82,14 @@ def ui
@ui ||= Ui.new
end

def json_parse(response, &block)
JSON.parse(response).inject([]) do |parsed_output, hash|
parsed_output << block.call(hash)
end.join("\n")
rescue JSON::ParserError
response
end

end
end
end
44 changes: 44 additions & 0 deletions lib/relish/commands/collab.rb
@@ -0,0 +1,44 @@
module Relish
module Command
class Collab < Base

desc 'list the collaborators for a project'
command :default do
puts format(resource[resource_path].get(:accept => :json))
end

usage 'collab:add <org_or_user_handle>/<project_handle>:' +
'<collaborator_handle_or_email>'
desc ['add a collaborator to a project',
'example: relish collab:add rspec/rspec-core:justin'].join("\n")
command :add do
puts resource[resource_path].post(:handle_or_email => handle_or_email)
end

usage 'collab:remove <org_or_user_handle>/<project_handle>:' +
'<collaborator_handle_or_email>'
desc ['remove a collaborator from a project',
'example: relish collab:remove rspec/rspec-core:justin'].join("\n")
command :remove do
puts resource["#{resource_path}/#{handle_or_email}"].delete
end

private

def resource_path
"projects/#{@param.remove_option}/memberships"
end

def handle_or_email
@param.extract_option
end

def format(response)
json_parse(response) do |hash|
"#{hash['user']['handle']} (#{hash['user']['email']})"
end
end

end
end
end
6 changes: 1 addition & 5 deletions lib/relish/commands/config.rb
Expand Up @@ -3,11 +3,7 @@ module Command
class Config < Base

desc 'display the contents of your options file'
command :default => :show

usage 'config:show'
desc 'display the contents of your options file'
command :show do
command :default do
puts(if File.exists?(Relish.local_options_file)
IO.read(Relish.local_options_file)
else
Expand Down
2 changes: 0 additions & 2 deletions lib/relish/commands/help.rb
@@ -1,5 +1,3 @@
require 'yaml'

module Relish
module Command
class Help < Base
Expand Down
23 changes: 8 additions & 15 deletions lib/relish/commands/projects.rb
@@ -1,22 +1,16 @@
require 'rubygems'
require 'json'

module Relish
module Command
class Projects < Base

desc 'list your projects'
command :default => :list

usage 'projects:list'

desc 'list your projects'
command :list do
response = resource['projects'].get(:accept => :json)
puts format(response)
command :default do
puts format(resource['projects'].get(:accept => :json))
end

usage 'projects:add <org_or_user_handle>/<project_handle>'
desc "add a project\nappend :private to make the project private\nexample: relish projects:add rspec/rspec-core:private"
desc ['add a project',
'append :private to make the project private',
'example: relish projects:add rspec/rspec-core:private'].join("\n")
command :add do
puts resource['projects'].post(:handle => handle, :private => private?)
end
Expand All @@ -29,12 +23,11 @@ class Projects < Base

private
def format(response)
json = JSON.parse(response)
json.map do |hash|
json_parse(response) do |hash|
result = hash['project']['full_handle']
result << " (private)" if hash['project']['private']
result
end.join("\n")
end
end

def handle
Expand Down
2 changes: 0 additions & 2 deletions lib/relish/commands/push.rb
@@ -1,9 +1,7 @@
require 'rubygems'
require 'zlib'
require 'archive/tar/minitar'
require 'stringio'
require 'rest_client'
require 'relish/commands/help'

module Relish
module Command
Expand Down
14 changes: 3 additions & 11 deletions spec/relish/commands/config_spec.rb
Expand Up @@ -4,16 +4,8 @@ module Relish
module Command
describe Config do

describe '#default' do
let(:config) { described_class.new }

it 'calls #show' do
config.should_receive(:show)
config.default
end
end

describe '#show' do
describe '#default' do
let(:config) { described_class.new }

context 'with a local options file' do
Expand All @@ -24,14 +16,14 @@ module Command

it 'outputs the contents' do
config.should_receive(:puts).with('options')
config.show
config.default
end
end

context 'without a local options file' do
it 'outputs the correct message' do
config.should_receive(:puts).with('No .relish file exists')
config.show
config.default
end
end
end
Expand Down
13 changes: 1 addition & 12 deletions spec/relish/commands/projects_spec.rb
Expand Up @@ -2,17 +2,6 @@

module Relish
module Command
describe Projects do

describe '#default' do
let(:projects) { described_class.new }

it 'calls #list' do
projects.should_receive(:list)
projects.default
end
end

end

end
end

0 comments on commit c8bf3f3

Please sign in to comment.