Class: Middleman::Cli::S3Sync

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/middleman-s3_sync/commands.rb', line 13

def self.exit_on_failure?
  true
end

Instance Method Details

#build(options = {}) ⇒ Object



104
105
106
107
108
# File 'lib/middleman-s3_sync/commands.rb', line 104

def build(options = {})
  if options[:build]
    run("middleman build -e #{options[:environment]}") || exit(1)
  end
end

#s3_syncObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/middleman-s3_sync/commands.rb', line 68

def s3_sync
  env = options[:environment].to_s.to_sym
  verbose = options[:verbose] ? 0 : 1
  instrument = options[:instrument]

  ::Middleman::S3Sync.app = ::Middleman::Application.new do
    config[:mode] = :build
    config[:environment] = env
    ::Middleman::Logger.singleton(verbose, instrument)
  end

  build(options)

  s3_sync_options = ::Middleman::S3Sync.s3_sync_options

  bucket = s3_sync_options.bucket rescue nil

  unless bucket
    raise Thor::Error.new 'You must provide the bucket name.'
  end

  # Override options based on what was passed on the command line...
  s3_sync_options.force = options[:force] if options[:force]
  s3_sync_options.aws_access_key_id = options[:aws_access_key_id] if options[:aws_access_key_id]
  s3_sync_options.aws_secret_access_key = options[:aws_secret_access_key] if options[:aws_secret_access_key]
  s3_sync_options.bucket = options[:bucket] if options[:bucket]
  s3_sync_options.verbose = options[:verbose] if options[:verbose]
  if options[:prefix]
    s3_sync_options.prefix  = options[:prefix] if options[:prefix]
    s3_sync_options.prefix = s3_sync_options.prefix.end_with?('/') ? s3_sync_options.prefix : s3_sync_options.prefix + '/'
  end
  s3_sync_options.dry_run = options[:dry_run] if options[:dry_run]

  ::Middleman::S3Sync.sync()
end