lib/travis/cli/command.rb in travis-1.6.2.travis.369.4 vs lib/travis/cli/command.rb in travis-1.6.2.travis.370.4
- old
+ new
@@ -61,12 +61,13 @@
def self.description(description = nil)
@description = description if description
@description ||= ""
end
- attr_accessor :arguments, :config, :force_interactive, :formatter
+ attr_accessor :arguments, :config, :force_interactive, :formatter, :debug
attr_reader :input, :output
+ alias_method :debug?, :debug
def initialize(options = {})
@on_signal = []
@formatter = Travis::Tools::Formatter.new
self.output = $stdout
@@ -203,15 +204,25 @@
def say(data, format = nil, style = nil)
terminal.say format(data, format, style)
end
def debug(line)
+ return unless debug?
write_to($stderr) do
say color("** #{line}", :debug)
end
end
+ def time(info, callback = Proc.new)
+ return callback.call unless debug?
+ start = Time.now
+ debug(info)
+ callback.call
+ duration = Time.now - start
+ debug(" took %.2g seconds" % duration)
+ end
+
def info(line)
write_to($stderr) do
say color(line, :info)
end
end
@@ -292,20 +303,24 @@
Dir.mkdir(path, 0700) unless File.directory? path
File.join(path, name)
end
def load_file(name, default = nil)
- path = config_path(name)
- File.exist?(path) ? File.read(path) : default
+ return default unless path = config_path(name) and File.exist? path
+ debug "Loading %p" % path
+ File.read(path)
end
def delete_file(name)
- path = config_path(name)
- File.delete(path) if File.exist?(path)
+ return unless path = config_path(name) and File.exist? path
+ debug "Deleting %p" % path
+ File.delete(path)
end
def save_file(name, content)
- File.write(config_path(name), content.to_s)
+ path = config_path(name)
+ debug "Storing %p" % path
+ File.write(path, content.to_s)
end
def load_config
@config = YAML.load load_file('config.yml', '{}')
@original_config = @config.dup