Class: Middleman::Cli::Rsync

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/middleman-rsync/commands.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Tell Thor to exit with a non-zero exit code on failure

Returns:

  • (Boolean)


19
20
21
# File 'lib/middleman-rsync/commands.rb', line 19

def self.exit_on_failure?
  true
end

Instance Method Details

#rsyncObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/middleman-rsync/commands.rb', line 23

def rsync
  unless environment == "staging" || environment == "production"
    raise Thor::Error, "Unknown environment '#{environment}'. Use 'staging' or 'production'."
  end

  app = ::Middleman::Application.new
  config = app.extensions[:rsync].options
  server = config["#{environment}_server".to_sym]

  if options[:build]
    puts "Building locally..."
    run("middleman build") || exit(1)
  end

  puts "\nReady for deployment to #{environment}: #{server}\n\n"

  if not ["yes", "y"].include?(ask("OK? [Yes|y|Y|No|n|N] > ").downcase)
    puts "\nExiting."
    exit(1)
  else
    puts
  end

  puts "Running rsync..."
  run("rsync #{config[:rsync_flags]} ./build/ #{config[:user]}@#{server}:#{config[:path]}")

  puts "Complete."
end