Skip to content

Commit

Permalink
Configuration refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chytreg committed Apr 24, 2013
1 parent ddd8925 commit 7b06d10
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 50 deletions.
24 changes: 8 additions & 16 deletions bin/webistrano_cli
@@ -1,25 +1,16 @@
#!/usr/bin/env ruby
require 'rubygems'
require 'slop'
require 'webistrano_cli'

require File.join(File.dirname(__FILE__), '../lib/webistrano_cli/config')
require File.join(File.dirname(__FILE__), '../lib/webistrano_cli/her_api_init')
config = WebistranoCli::Config.new
config.setup_and_load!

WebistranoCli::API = Her::API.new
WebistranoCli::API.setup :url => config.get_value('url') do |c|
c.headers['Accept'] = 'application/xml'
c.headers['Content-Type'] = 'application/xml'
c.basic_auth config.get_value('user'), config.get_value('password')
c.response :logger if ENV['WCLI_DEBUG']
c.use HerXmlParser
c.use HerXMLPost
c.adapter Faraday.default_adapter
end

# load api related models
require File.join(File.dirname(__FILE__), '../lib/webistrano_cli')
WebistranoCli.configure(
config.get_value('url'),
config.get_value('user'),
config.get_value('password')
)

# parse assumes ARGV, otherwise you can pass it your own Array
opts = Slop.new :help => true do
Expand All @@ -40,7 +31,8 @@ begin
hash[:project] = File.split(Dir.pwd).last
puts "No project param, used current dir name."
end
WebistranoCli.deploy(hash, config)
raise hash.inspect
WebistranoCli.deploy(hash)
rescue Slop::Error => ex
puts ex.message
end
31 changes: 24 additions & 7 deletions lib/webistrano_cli.rb
@@ -1,16 +1,33 @@
# -*- encoding: utf-8 -*-
require 'rubygems'
require 'highline/import'
require File.join(File.dirname(__FILE__), 'webistrano_cli/version')
require File.join(File.dirname(__FILE__), 'webistrano_cli/project')
require File.join(File.dirname(__FILE__), 'webistrano_cli/stage')
require File.join(File.dirname(__FILE__), 'webistrano_cli/task')
require File.join(File.dirname(__FILE__), 'webistrano_cli/deployment')
require 'webistrano_cli/version'
require 'webistrano_cli/config'
require 'webistrano_cli/her_middlewares'

module WebistranoCli
class << self
def deploy opts = {}, config
Task.new(opts[:project], config.stage(opts[:stage]), config.task(opts[:task])).run

def configure(url, user, pass, &block)
WebistranoCli::API.setup :url => user do |c|
c.basic_auth user, pass
c.headers = {
'Accept' => 'application/xml'
'Content-Type' => 'application/xml'
}
c.response :logger if ENV['WCLI_DEBUG']
c.use HerXmlParser
c.use HerXMLPost
c.adapter Faraday.default_adapter

yield c if block_given?
end
require 'webistrano_cli/models'
require 'webistrano_cli/task'
end

def deploy opts = {}
Task.new(*opts.values).run
end
end
end
13 changes: 6 additions & 7 deletions lib/webistrano_cli/config.rb
Expand Up @@ -9,7 +9,7 @@ def initialize
end

def load!(path)
@config = YAML.load_file(path)
@config = YAML.load_file(path)
end

def setup_and_load!
Expand All @@ -29,12 +29,11 @@ def setup_and_load!
save_yaml
end

def stage opt
opt || get_value('defaults/stage') || 'staging'
end

def task opt
opt || get_value('defaults/task') || 'deploy:migrations'
def defaults
{
:stage => get_value('defaults/stage') || 'staging',
:task => get_value('defaults/task') || 'deploy:migrations'
}
end

def get_value(path)
Expand Down
10 changes: 0 additions & 10 deletions lib/webistrano_cli/deployment.rb

This file was deleted.

File renamed without changes.
19 changes: 17 additions & 2 deletions lib/webistrano_cli/stage.rb → lib/webistrano_cli/models.rb
@@ -1,5 +1,21 @@
# -*- encoding: utf-8 -*-
require 'mechanize'

module WebistranoCli

class Deployment
include Her::Model
uses_api WebistranoCli::API
collection_path "projects/:project_id/stages/:stage_id/deployments"
include_root_in_json :deployment
end

class Project
include Her::Model
uses_api WebistranoCli::API
has_many :stages
end

class Stage
include Her::Model
uses_api WebistranoCli::API
Expand Down Expand Up @@ -34,7 +50,6 @@ def get_task_config(name)
end
prompt_config.presence
end

end
end

end
8 changes: 0 additions & 8 deletions lib/webistrano_cli/project.rb

This file was deleted.

0 comments on commit 7b06d10

Please sign in to comment.