add the missing push command (+ spec)

did committed Apr 09, 2015
commit 79c5055d1c480467e6129f50cc9c8e064f49a762
Showing 2 changed files with 103 additions and 0 deletions
locomotive/wagon/commands/push_command.rb b/lib/locomotive/wagon/commands/push_command.rb +70 -0
@@ @@ -0,0 +1,70 @@
+ require 'locomotive/coal'
+ require 'netrc'
+
+ module Locomotive::Wagon
+
+ class PushCommand < Struct.new(:env, :path, :options)
+
+ def push
+ puts read_from_yaml_file.inspect
+ true
+ end
+
+ def connection_information
+ if information = read_from_yaml_file
+ # the site should exist
+ information
+ else
+ # TODO
+ # 1. ask for the platform URL (or LOCOMOTIVE_PLATFORM_URL env variable)
+ platform_url = shell.ask "Enter the URL of your platform? (default: #{default_platform_url})"
+
+ puts platform_url
+
+ # 2. retrieve email + api_key
+ # 3. get an instance of the Steam services => common to the read_from_yaml_file way
+ # 4. load the information about the site (SiteRepository)
+ # 5. ask for a handle if not found (blank: random one)
+ # 6. create the site
+ # 7. update the deploy.yml
+ end
+
+ # clean the URI (ssl, without scheme?)
+ # assign the site to the Steam services and repositories
+ # build an instance of the Coal client class
+ end
+
+
+
+ private
+
+ def shell
+ options[:shell]
+ end
+
+ def default_platform_url
+ ENV['LOCOMOTIVE_PLATFORM_URL'] || DEFAULT_PLATFORM_URL
+ end
+
+ def deploy_file
+ File.join(path, 'config', 'deploy.yml')
+ end
+
+ def read_from_yaml_file
+ # pre-processing: erb code to parse and render?
+ parsed_deploy_file = ERB.new(File.open(deploy_file).read).result
+
+ # finally, get the hash from the YAML file
+ environments = YAML::load(parsed_deploy_file)
+ (environments.is_a?(Hash) ? environments : {})[env.to_s]
+ rescue Exception => e
+ raise "Unable to read the config/deploy.yml file (#{e.message})"
+ end
+
+ def read_from_netrc
+
+ end
+
+ end
+
+ end
spec/integration/commands/push_command_spec.rb +33 -0
@@ @@ -0,0 +1,33 @@
+ # encoding: utf-8
+
+ require File.dirname(__FILE__) + '/../integration_helper'
+ require 'locomotive/wagon/commands/push_command'
+ require 'thor'
+
+ describe Locomotive::Wagon::PushCommand do
+
+ # before { VCR.insert_cassette 'push', record: :new_episodes, match_requests_on: [:method, :query, :body] }
+ # after { VCR.eject_cassette }
+
+ # let(:platform_url) { TEST_PLATFORM_URL }
+ let(:env) { 'production' }
+ let(:path) { default_site_path }
+ let(:shell) { Thor::Shell::Color.new }
+ let(:options) { { shell: shell } }
+ let(:command) { described_class.new(env, path, options) }
+
+ describe '#push' do
+
+ subject { command.push }
+
+ context 'unknown env' do
+
+ let(:env) { 'hosting' }
+
+ it { is_expected.to eq true }
+
+ end
+
+ end
+
+ end