bin/ridgepole in ridgepole-0.4.7 vs bin/ridgepole in ridgepole-0.4.8.rc1
- old
+ new
@@ -32,15 +32,27 @@
raise 'More than one mode is specified' if mode
mode = m
end
def noop_migrate(delta)
- puts delta.script + "\n\n"
+ unless delta.script.empty?
+ puts delta.script + "\n\n"
+ end
- delta.migrate(:noop => true).each_line do |line|
- puts line.strip.gsub(/([^\d])([(),])([^\d])/) { "#{$1}#{$2}\n#{$3}" }.each_line.map {|i| "# #{i.gsub(/^\s+/, '')}"}.join + "\n\n"
+ migrated, out = delta.migrate(:noop => true)
+
+ if migrated
+ out.each_line do |line|
+ if line =~ /\A\s+/
+ puts "# #{line}"
+ else
+ puts line.strip.gsub(/([^\d])([(),])([^\d])/) { "#{$1}#{$2}\n#{$3}" }.each_line.map {|i| "# #{i.gsub(/^\s+/, '')}"}.join + "\n"
+ end
+ end
end
+
+ return migrated
end
ARGV.options do |opt|
begin
opt.on('-c', '--config CONF_OR_FILE') {|v| config = v }
@@ -159,21 +171,22 @@
msg << ' (dry-run)' if options[:dry_run]
logger.info(msg)
dsl = File.read(file)
delta = client.diff(dsl, :path => file)
+ differ = delta.differ?
if options[:dry_run]
- if delta.differ?
- noop_migrate(delta)
+ if differ
+ differ = noop_migrate(delta)
end
else
logger.verbose_info('# Update schema')
- delta.migrate
+ differ, out = delta.migrate
end
- unless delta.differ?
+ unless differ
logger.info('No change')
end
when :diff
diff_files = diff_files.map do |file|
if File.exist?(file)
@@ -191,18 +204,21 @@
delta = Ridgepole::Client.diff(*diff_files, options)
if diff_with_apply
logger.verbose_info('# Update schema')
+ differ = delta.differ?
- if delta.differ?
- delta.migrate
- else
+ if differ
+ differ, out = delta.migrate
+ end
+
+ if differ
logger.info('No change')
end
elsif delta.differ?
- noop_migrate(delta)
- exit_code = 1
+ differ = noop_migrate(delta)
+ exit_code = 1 if differ
end
end
rescue => e
if options[:debug]
raise e