Module: CLIClassTool::Logger

Included in:
Common
Defined in:
lib/cli_class_tool/common.rb

Overview

Logger for CLIClassTool::Common

Instance Method Summary collapse

Instance Method Details

#confirm(opts, msg, ignore_default = false, allowed_reps = [ "y", "n" ]) ⇒ String

Prompt the user for confirmation

Parameters:

  • opts (Hash)

    Options hash

  • msg (String)

    Confirmation message

  • ignore_default (Boolean) (defaults to: false)

    Ignore default yes/no options

  • allowed_reps (Array<String>) (defaults to: [ "y", "n" ])

    Allowed responses

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/cli_class_tool/common.rb', line 82

def confirm(opts, msg, ignore_default=false, allowed_reps=[ "y", "n" ])
    rep = 't'
    while allowed_reps.index(rep) == nil && rep != '' do
        puts "Do you wish to #{msg} ? (#{allowed_reps.join("/")}): "
        case (ignore_default == true ? nil : opts[:yn_default])
        when :no
            puts "Auto-replying no due to --no option"
            rep = 'n'
        when :yes
            puts "Auto-replying yes due to --yes option"
            rep = 'y'
        else
            rep = STDIN.gets.chomp()
        end
    end
    return rep
end

#log(lvl, str) ⇒ Object

Log a message with a specific level

Parameters:

  • lvl (Symbol)

    Log level (:DEBUG, :INFO, :WARNING, :ERROR, etc.)

  • str (String)

    Message to log



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cli_class_tool/common.rb', line 54

def log(lvl, str)
    case lvl
    when :DEBUG
        _log("DEBUG".magenta(), str) if ENV["DEBUG"].to_s() != ""
    when :DEBUG_CI
        _log("DEBUG_CI".magenta(), str) if ENV["DEBUG_CI"].to_s() != ""
    when :VERBOSE
        _log("INFO".blue(), str) if parent_module.verbose_log == true
    when :INFO
        _log("INFO".green(), str)
    when :PROGRESS
        _relog("INFO".green(), str)
    when :WARNING
        _log("WARNING".brown(), str)
    when :ERROR
        _log("ERROR".red(), str, $stderr)
    else
        _log(lvl, str)
    end
end