destroy command refactored
did
committed Jul 30, 2015
commit 08d519e377c41b409586e1ed367b2db5f2409eed
Showing 5
changed files with
42 additions
and 35 deletions
bin/wagon
+1
-1
| @@ | @@ -9,4 +9,4 @@ $stdout.sync = true |
| require 'locomotive/wagon' | |
| require 'locomotive/wagon/cli' | |
| - | Locomotive::Wagon::CLI::Main.start |
| \ No newline at end of file | |
| + | Locomotive::Wagon::CLI::Main.start |
locomotive/wagon.rb b/lib/locomotive/wagon.rb
+5
-27
| @@ | @@ -99,36 +99,14 @@ module Locomotive |
| # Destroy a remote site | |
| # | |
| + | # @param [ String ] env The environment we use to deploy the site to |
| # @param [ String ] path The path of the site | |
| - | # @param [ Hash ] connection_info The information to get connected to the remote site |
| - | # @param [ Hash ] options The options passed to the push process |
| + | # @param [ Hash ] options The options passed to the destroy command |
| # | |
| - | def self.destroy(path, connection_info, options = {}) |
| - | raise 'TODO' |
| - | # self.require_mounter(path) |
| - | |
| - | # connection_info['uri'] = "#{connection_info.delete('host')}/locomotive/api" |
| - | |
| - | # Locomotive::Mounter::EngineApi.set_token connection_info.symbolize_keys |
| - | # Locomotive::Mounter::EngineApi.delete('/current_site.json') |
| + | def self.destroy(env, path, options = {}) |
| + | require_relative 'wagon/commands/destroy_command' |
| + | Locomotive::Wagon::DestroyCommand.destroy(env, path, options) |
| end | |
| - | # protected |
| - | |
| - | # def self.validate_resources(resources, writers_or_readers) |
| - | # return if resources.nil? |
| - | |
| - | # # FIXME: for an unknown reason, when called from Cocoa, the resources are a string |
| - | # resources = resources.map { |resource| resource.split(' ') }.flatten |
| - | |
| - | # valid_resources = writers_or_readers.map { |thing| thing.to_s.demodulize.gsub(/Writer$|Reader$/, '').underscore } |
| - | |
| - | # resources.each do |resource| |
| - | # raise ArgumentError, "'#{resource}' resource not recognized. Valid resources are #{valid_resources.join(', ')}." unless valid_resources.include?(resource) |
| - | # end |
| - | |
| - | # resources |
| - | # end |
| - | |
| end | |
| end | |
locomotive/wagon/cli.rb b/lib/locomotive/wagon/cli.rb
+5
-7
| @@ | @@ -335,13 +335,11 @@ module Locomotive |
| desc 'destroy ENV [PATH]', 'Destroy a remote LocomotiveCMS Engine' | |
| def destroy(env, path = '.') | |
| if check_path!(path) | |
| - | if connection_info = self.retrieve_connection_info(env, path) |
| - | if ask('Are you sure ?', limited_to: %w(yes no)) == 'yes' |
| - | Locomotive::Wagon.destroy(path, connection_info) |
| - | else |
| - | say 'The destroy operation has been cancelled', :red |
| - | exit(1) |
| - | end |
| + | if ask('Are you sure?', limited_to: %w(yes no)) == 'yes' |
| + | Locomotive::Wagon.destroy(env, path) |
| + | else |
| + | say 'The destroy operation has been cancelled', :red |
| + | exit(1) |
| end | |
| end | |
| end | |
locomotive/wagon/commands/destroy_command.rb b/lib/locomotive/wagon/commands/destroy_command.rb
+29
-0
| @@ | @@ -0,0 +1,29 @@ |
| + | require_relative 'concerns/api_concern' |
| + | require_relative 'concerns/deploy_file_concern' |
| + | |
| + | module Locomotive::Wagon |
| + | |
| + | class DestroyCommand < Struct.new(:env, :path, :options) |
| + | |
| + | include ApiConcern |
| + | include DeployFileConcern |
| + | |
| + | def self.destroy(env, path, options) |
| + | self.new(env, path, options).destroy |
| + | end |
| + | |
| + | def destroy |
| + | api_client = api_site_client(connection_information) |
| + | |
| + | api_client.current_site.destroy |
| + | end |
| + | |
| + | private |
| + | |
| + | def connection_information |
| + | read_deploy_settings(self.env, self.path) |
| + | end |
| + | |
| + | end |
| + | |
| + | end |
locomotive/wagon/commands/pull_sub_commands/pull_site_command.rb b/lib/locomotive/wagon/commands/pull_sub_commands/pull_site_command.rb
+2
-0
| @@ | @@ -23,6 +23,8 @@ module Locomotive::Wagon |
| private | |
| def write_icon(url) | |
| + | return if url.blank? |
| + | |
| unless url =~ /\Ahttp:\/\// | |
| base = api_client.uri.dup.tap { |u| u.path = '' }.to_s | |
| url = URI.join(base, url).to_s | |