-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
131 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'clamp' | ||
require_relative 'clamp_help_formatter' | ||
|
||
module Kubetruth | ||
class CLIBase < Clamp::Command | ||
|
||
include GemLogger::LoggerSupport | ||
|
||
option ["-q", "--quiet"], | ||
:flag, "Suppress output", | ||
default: false | ||
|
||
option ["-d", "--debug"], | ||
:flag, "Debug output", | ||
default: false | ||
|
||
option ["-c", "--[no-]color"], | ||
:flag, "colorize output (or not) (default: $stdout.tty?)", | ||
default: true | ||
|
||
option ["-v", "--version"], | ||
:flag, "show version" do | ||
logger.info "Version #{VERSION}" | ||
exit(0) | ||
end | ||
|
||
# hook into clamp lifecycle to force logging setup even when we are calling | ||
# a subcommand | ||
def parse(arguments) | ||
super | ||
|
||
level = :info | ||
level = :debug if debug? | ||
level = :error if quiet? | ||
Kubetruth::Logging.setup_logging(level: level, color: color?) | ||
end | ||
|
||
def execute | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'rspec' | ||
require 'kubetruth/cli_base' | ||
|
||
module Kubetruth | ||
describe CLIBase do | ||
|
||
let(:cli) { described_class.new("") } | ||
|
||
describe "--help" do | ||
|
||
it "produces help text under standard width" do | ||
all_usage(described_class).each do |m| | ||
expect(m[:usage]).to be_line_width_for_cli(m[:name]) | ||
end | ||
end | ||
|
||
end | ||
|
||
describe "version" do | ||
|
||
it "uses flag to produce version text" do | ||
expect { cli.run(['--version']) }.to raise_error(SystemExit) | ||
expect(Logging.contents).to include(VERSION) | ||
end | ||
|
||
end | ||
|
||
describe "--debug" do | ||
|
||
it "defaults to info log level" do | ||
expect(Logging).to receive(:setup_logging).with(hash_including(level: :info)) | ||
cli.run([]) | ||
end | ||
|
||
it "sets log level to debug" do | ||
expect(Logging).to receive(:setup_logging).with(hash_including(level: :debug)) | ||
cli.run(['--debug']) | ||
end | ||
|
||
end | ||
|
||
describe "--quiet" do | ||
|
||
it "defaults to info log level" do | ||
expect(Logging).to receive(:setup_logging).with(hash_including(level: :info)) | ||
cli.run([]) | ||
end | ||
|
||
it "sets log level to warn" do | ||
expect(Logging).to receive(:setup_logging).with(hash_including(level: :error)) | ||
cli.run(['--quiet']) | ||
end | ||
|
||
end | ||
|
||
describe "--no-color" do | ||
|
||
it "defaults to color" do | ||
expect(Logging).to receive(:setup_logging).with(hash_including(color: true)) | ||
cli.run([]) | ||
end | ||
|
||
it "outputs plain text" do | ||
expect(Logging).to receive(:setup_logging).with(hash_including(color: false)) | ||
cli.run(['--no-color']) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters