summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--leap_cli.gemspec8
-rw-r--r--lib/leap_cli/log.rb56
-rw-r--r--lib/leap_cli/remote/leap_plugin.rb2
3 files changed, 52 insertions, 14 deletions
diff --git a/leap_cli.gemspec b/leap_cli.gemspec
index fc3131f..b0a15a9 100644
--- a/leap_cli.gemspec
+++ b/leap_cli.gemspec
@@ -45,14 +45,10 @@ spec = Gem::Specification.new do |s|
# test
s.add_development_dependency('minitest', '~> 5.0')
- #s.add_development_dependency('rdoc')
- #s.add_development_dependency('aruba')
-
# console gems
s.add_runtime_dependency('gli','~> 2.14', '>= 2.14.0')
# note: gli version is also pinned in leap_cli.rb.
s.add_runtime_dependency('command_line_reporter', '~> 3.3')
- s.add_runtime_dependency('paint', '~> 0.9')
# network gems
s.add_runtime_dependency('net-ssh', '~> 2.7')
@@ -61,14 +57,10 @@ spec = Gem::Specification.new do |s|
s.add_runtime_dependency('capistrano', '~> 2.15')
# crypto gems
- #s.add_runtime_dependency('certificate_authority', '>= 0.2.0')
- # ^^ currently vendored
# s.add_runtime_dependency('gpgme') # << does not build on debian jessie, so now optional.
# also, there is a ruby-gpgme package anyway.
# misc gems
s.add_runtime_dependency('ya2yaml', '~> 0.31') # pure ruby yaml, so we can better control output. see https://github.com/afunai/ya2yaml
s.add_runtime_dependency('json_pure', '~> 1.8') # pure ruby json, so we can better control output.
- s.add_runtime_dependency('base32', '~> 0.3') # base32 encoding
-
end
diff --git a/lib/leap_cli/log.rb b/lib/leap_cli/log.rb
index 0497275..c83b385 100644
--- a/lib/leap_cli/log.rb
+++ b/lib/leap_cli/log.rb
@@ -1,11 +1,11 @@
-require 'paint'
-
##
## LOGGING
##
module LeapCli
module LogCommand
+ @@logger = nil
+
def log(*args)
logger.log(*args)
end
@@ -15,7 +15,12 @@ module LeapCli
end
def logger
- @logger ||= LeapCli::LeapLogger.new
+ @@logger ||= LeapCli::LeapLogger.new
+ end
+
+ # deprecated
+ def log_level
+ logger.log_level
end
end
end
@@ -36,6 +41,7 @@ module LeapCli
@indent_level = 0
@log_file = nil
@log_output_stream = nil
+ @log_in_color = true
end
def log_file=(value)
@@ -95,10 +101,10 @@ module LeapCli
end
if options[:host]
clear_prefix = "[%s] %s " % [options[:host], prefix_options[0]]
- colored_prefix = "[%s] %s " % [Paint[options[:host], prefix_options[1], prefix_options[2]], prefix_options[0]]
+ colored_prefix = "[%s] %s " % [colorize(options[:host], prefix_options[1], prefix_options[2]), prefix_options[0]]
else
clear_prefix = "%s " % prefix_options[0]
- colored_prefix = "%s " % Paint[prefix_options[0], prefix_options[1], prefix_options[2]]
+ colored_prefix = "%s " % colorize(prefix_options[0], prefix_options[1], prefix_options[2])
end
elsif options[:host]
clear_prefix = colored_prefix = "[%s] " % options[:host]
@@ -163,5 +169,45 @@ module LeapCli
end
end
+ def colorize(str, color, style=nil)
+ codes = [FG_COLORS[color] || FG_COLORS[:default]]
+ if style
+ codes << EFFECTS[style] || EFFECTS[:nothing]
+ end
+ ["\033[%sm" % codes.join(';'), str, NO_COLOR].join
+ end
+
+ private
+
+ EFFECTS = {
+ :reset => 0, :nothing => 0,
+ :bright => 1, :bold => 1,
+ :underline => 4,
+ :inverse => 7, :swap => 7,
+ }
+ NO_COLOR = "\033[0m"
+ FG_COLORS = {
+ :black => 30,
+ :red => 31,
+ :green => 32,
+ :yellow => 33,
+ :blue => 34,
+ :magenta => 35,
+ :cyan => 36,
+ :white => 37,
+ :default => 39,
+ }
+ BG_COLORS = {
+ :black => 40,
+ :red => 41,
+ :green => 42,
+ :yellow => 43,
+ :blue => 44,
+ :magenta => 45,
+ :cyan => 46,
+ :white => 47,
+ :default => 49,
+ }
+
end
end \ No newline at end of file
diff --git a/lib/leap_cli/remote/leap_plugin.rb b/lib/leap_cli/remote/leap_plugin.rb
index ee33cea..e6305ae 100644
--- a/lib/leap_cli/remote/leap_plugin.rb
+++ b/lib/leap_cli/remote/leap_plugin.rb
@@ -10,7 +10,7 @@ module LeapCli; module Remote; module LeapPlugin
end
def log(*args, &block)
- LeapCli::Util::log(*args, &block)
+ LeapCli.logger.log(*args, &block)
end
#