Merge branch 'debug-option'
This commit is contained in:
commit
6f38ad2990
5
features/cli/debug.feature
Normal file
5
features/cli/debug.feature
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Feature: debug CLI option
|
||||||
|
|
||||||
|
Scenario: raises the logger level to DEBUG
|
||||||
|
When I run uhwm with option -d
|
||||||
|
Then the current output must match /log.+debug.+level/i
|
@ -22,6 +22,7 @@ Usage: uhwm [options]
|
|||||||
options:
|
options:
|
||||||
-h, --help print this message
|
-h, --help print this message
|
||||||
-v, --version enable verbose mode
|
-v, --version enable verbose mode
|
||||||
|
-d, --debug enable debug mode
|
||||||
eoh
|
eoh
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,6 +53,11 @@ module Uh
|
|||||||
@env.verbose = true
|
@env.verbose = true
|
||||||
@env.log_logger_level
|
@env.log_logger_level
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.on '-d', '--debug', 'enable debug mode' do
|
||||||
|
@env.debug = true
|
||||||
|
@env.log_logger_level
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,6 +3,7 @@ module Uh
|
|||||||
class Env
|
class Env
|
||||||
LOGGER_LEVEL = Logger::WARN
|
LOGGER_LEVEL = Logger::WARN
|
||||||
LOGGER_LEVEL_VERBOSE = Logger::INFO
|
LOGGER_LEVEL_VERBOSE = Logger::INFO
|
||||||
|
LOGGER_LEVEL_DEBUG = Logger::DEBUG
|
||||||
LOGGER_LEVEL_STRINGS = %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]
|
LOGGER_LEVEL_STRINGS = %w[DEBUG INFO WARN ERROR FATAL UNKNOWN]
|
||||||
|
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
@ -10,7 +11,7 @@ module Uh
|
|||||||
def_delegator :@output, :print
|
def_delegator :@output, :print
|
||||||
|
|
||||||
attr_reader :output
|
attr_reader :output
|
||||||
attr_accessor :verbose
|
attr_accessor :verbose, :debug
|
||||||
|
|
||||||
def initialize output
|
def initialize output
|
||||||
@output = output
|
@output = output
|
||||||
@ -20,9 +21,14 @@ module Uh
|
|||||||
!!@verbose
|
!!@verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def debug?
|
||||||
|
!!@debug
|
||||||
|
end
|
||||||
|
|
||||||
def logger
|
def logger
|
||||||
@logger ||= Logger.new(@output).tap do |o|
|
@logger ||= Logger.new(@output).tap do |o|
|
||||||
o.level = verbose? ? LOGGER_LEVEL_VERBOSE : LOGGER_LEVEL
|
o.level = debug? ? LOGGER_LEVEL_DEBUG :
|
||||||
|
verbose? ? LOGGER_LEVEL_VERBOSE : LOGGER_LEVEL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,6 +102,20 @@ module Uh
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with debug option' do
|
||||||
|
let(:arguments) { %w[-d] }
|
||||||
|
|
||||||
|
it 'sets the env as debug' do
|
||||||
|
cli.parse_arguments!
|
||||||
|
expect(cli.env).to be_debug
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'tells the env to log its logger level' do
|
||||||
|
expect(cli.env).to receive :log_logger_level
|
||||||
|
cli.parse_arguments!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with invalid option' do
|
context 'with invalid option' do
|
||||||
let(:arguments) { %w[--unknown-option] }
|
let(:arguments) { %w[--unknown-option] }
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@ module Uh
|
|||||||
expect(env).not_to be_verbose
|
expect(env).not_to be_verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'has debug mode disabled' do
|
||||||
|
expect(env).not_to be_debug
|
||||||
|
end
|
||||||
|
|
||||||
describe '#verbose?' do
|
describe '#verbose?' do
|
||||||
context 'when verbose mode is disabled' do
|
context 'when verbose mode is disabled' do
|
||||||
before { env.verbose = false }
|
before { env.verbose = false }
|
||||||
@ -27,6 +31,24 @@ module Uh
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#debug?' do
|
||||||
|
context 'when debug mode is disabled' do
|
||||||
|
before { env.debug = false }
|
||||||
|
|
||||||
|
it 'returns false' do
|
||||||
|
expect(env.debug?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when debug mode is enabled' do
|
||||||
|
before { env.debug = true }
|
||||||
|
|
||||||
|
it 'returns true' do
|
||||||
|
expect(env.debug?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#logger' do
|
describe '#logger' do
|
||||||
it 'returns a logger' do
|
it 'returns a logger' do
|
||||||
expect(env.logger).to be_a Logger
|
expect(env.logger).to be_a Logger
|
||||||
@ -39,9 +61,17 @@ module Uh
|
|||||||
context 'when verbose mode is enabled' do
|
context 'when verbose mode is enabled' do
|
||||||
before { env.verbose = true }
|
before { env.verbose = true }
|
||||||
|
|
||||||
it 'has logger level info set' do
|
it 'has logger level info set' do
|
||||||
expect(env.logger.level).to be Logger::INFO
|
expect(env.logger.level).to be Logger::INFO
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when debug mode is enabled' do
|
||||||
|
before { env.debug = true }
|
||||||
|
|
||||||
|
it 'has logger level debug set' do
|
||||||
|
expect(env.logger.level).to be Logger::DEBUG
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user