module Publisher::Helpers
Attributes
Public Class Methods
Colorize string
@param [String] message @param [Symbol] color @return [String]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 33 def colorize(message, color) Helpers.pastel.decorate(message, color) end
Print error message and exit
@param [String] message @return [void]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 50 def error(message) warn colorize(message, :red) exit(1) end
Execute shell command
@param [String] command @return [String] output
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 67 def execute_shell(command) out, err, status = Open3.capture3(command) raise("Out:\n#{out}\n\nErr:\n#{err}") unless status.success? out end
Log message to stdout
@param [String] message @param [String] color @return [void]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 42 def log(message, color = :magenta) puts colorize(message, color) end
Global instance of pastel
@param [Boolean] force_color @return [Pastel]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 12 def self.pastel(force_color: nil) @pastel ||= Pastel.new(enabled: force_color, eachline: "\n") end
Safe join path
@param [Array<String>] *args @return [String]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 59 def path(*args) File.join(args).to_s end
Check allure cli is installed and executable
@return [void]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 19 def self.validate_allure_cli_present _out, status = Open3.capture2("which allure") return if status.success? Helpers.error( "Allure cli is missing! See https://docs.qameta.io/allure/#_installing_a_commandline on how to install it!" ) end
Private Instance Methods
Colorize string
@param [String] message @param [Symbol] color @return [String]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 33 def colorize(message, color) Helpers.pastel.decorate(message, color) end
Print error message and exit
@param [String] message @return [void]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 50 def error(message) warn colorize(message, :red) exit(1) end
Error message color
@return [Symbol]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 49 def error_color @error_color ||= exit_on_error ? :red : :yellow end
Error mark
@return [String]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 63 def error_mark colorize(TTY::Spinner::CROSS, error_color) end
Execute shell command
@param [String] command @return [String] output
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 67 def execute_shell(command) out, err, status = Open3.capture3(command) raise("Out:\n#{out}\n\nErr:\n#{err}") unless status.success? out end
Log message to stdout
@param [String] message @param [String] color @return [void]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 42 def log(message, color = :magenta) puts colorize(message, color) end
Safe join path
@param [Array<String>] *args @return [String]
# File lib/allure_report_publisher/lib/helpers/helpers.rb, line 59 def path(*args) File.join(args).to_s end
Spinner
instance
@return [TTY::Spinner]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 70 def spinner @spinner ||= TTY::Spinner.new( "[:spinner] #{spinner_message} ...", format: :dots, success_mark: success_mark, error_mark: error_mark ) end
Return spinner error
@param [String] error_message @return [void]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 101 def spinner_error(error_message) colored_message = colorize("failed\n#{error_message}", error_color) return spinner.error(colored_message) if tty? spinner.stop puts("[#{error_mark}] #{spinner_message} ... #{colored_message}") end
Return spinner success
@param [String] done_message @return [void]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 90 def spinner_success(done_message) return spinner.success(done_message) if tty? spinner.stop puts("[#{success_mark}] #{spinner_message} ... #{done_message}") end
Success mark
@return [String]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 56 def success_mark @success_mark ||= colorize(TTY::Spinner::TICK, :green) end
Check tty
@return [Boolean]
# File lib/allure_report_publisher/lib/helpers/spinner.rb, line 82 def tty? spinner.send(:tty?) end