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

Commit

Permalink
add api_token to project options file
Browse files Browse the repository at this point in the history
  • Loading branch information
justinko committed Nov 4, 2010
1 parent 7ff9b98 commit caab8d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
32 changes: 20 additions & 12 deletions lib/relish/commands/base.rb
Expand Up @@ -7,40 +7,40 @@ class Base
GLOBAL_OPTIONS_FILE = File.join(File.expand_path('~'), '.relish')
LOCAL_OPTIONS_FILE = '.relish'

attr_accessor :args
attr_writer :args

def initialize(args = [])
@args = args
@args = clean_args(args)
@param = get_param
@options = get_options
end

def organization
@options['--organization'] || parsed_options_file['organization']
@options['organization']
end

def project
@options['--project'] || parsed_options_file['project']
@options['project']
end

def api_token
@options['api_token']
end

def url
"http://#{@options['--host'] || DEFAULT_HOST}/api"
"http://#{@options['host'] || DEFAULT_HOST}/api"
end

def resource
RestClient::Resource.new(url)
end

def api_token
parsed_options_file['api_token']
end


def get_param
args.shift if args.size.odd?
@args.shift if @args.size.odd?
end

def get_options
parsed_options_file.merge(Hash[*args])
parsed_options_file.merge(Hash[*@args])
end

def parsed_options_file
Expand All @@ -51,6 +51,14 @@ def parsed_options_file
end
end

def clean_args(args)
cleaned = []
args.each do |arg|
cleaned << arg.sub('--', '')
end
cleaned
end

end
end
end
4 changes: 3 additions & 1 deletion lib/relish/commands/config.rb
Expand Up @@ -15,7 +15,9 @@ def show
end

def add
raise args.inspect
File.open(LOCAL_OPTIONS_FILE, 'a') do |f|
f.write(YAML::dump(Hash[*@args]))
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/relish/commands/push.rb
Expand Up @@ -36,7 +36,7 @@ def parameters
end

def version
@options['--version'] || @options['-v']
@options['version']
end

def files_as_tar_gz
Expand Down
13 changes: 2 additions & 11 deletions spec/relish/commands/base_spec.rb
Expand Up @@ -6,23 +6,14 @@ module Command

{:organization => 'rspec', :project => 'rspec-core'}.each do |meth, name|
describe "##{meth}" do
context 'passed in command line as full arg' do
context 'passed in command line' do
let(:base) { described_class.new(["--#{meth}", name]) }

it 'returns the value' do
base.send(meth).should eq(name)
end
end

context 'passed in command line as short arg' do
let(:short_arg) { meth.to_s[0,1] }
let(:base) { described_class.new(["-#{short_arg}", name]) }

it 'returns the value' do
base.send(meth).should eq(name)
end
end

context 'contained in the options file' do
let(:base) { described_class.new }

Expand Down Expand Up @@ -123,7 +114,7 @@ module Command

it 'combines the args and options file' do
base.get_options.should eq(
{'project' => 'rspec-core', '--project' => 'rspec-core'}
{'project' => 'rspec-core'}
)
end
end
Expand Down

0 comments on commit caab8d6

Please sign in to comment.