lib/goodcheck/cli.rb in goodcheck-1.3.1 vs lib/goodcheck/cli.rb in goodcheck-1.4.0
- old
+ new
@@ -1,7 +1,9 @@
require "optparse"
+Version = Goodcheck::VERSION
+
module Goodcheck
class CLI
attr_reader :stdout
attr_reader :stderr
@@ -33,15 +35,25 @@
stderr.puts " #{bt}"
end
1
end
+ def home_path
+ if (path = ENV["GOODCHECK_HOME"])
+ Pathname(path)
+ else
+ Pathname(Dir.home) + ".goodcheck"
+ end
+ end
+
def check(args)
config_path = Pathname("goodcheck.yml")
targets = []
rules = []
format = nil
+ loglevel = Logger::ERROR
+ force_download = false
OptionParser.new("Usage: goodcheck check [options] dirs...") do |opts|
opts.on("-c CONFIG", "--config=CONFIG") do |config|
config_path = Pathname(config)
end
@@ -49,12 +61,23 @@
rules << rule
end
opts.on("--format=<text|json> [default: 'text']") do |f|
format = f
end
+ opts.on("-v", "--verbose") do
+ loglevel = Logger::INFO
+ end
+ opts.on("-d", "--debug") do
+ loglevel = Logger::DEBUG
+ end
+ opts.on("--force") do
+ force_download = true
+ end
end.parse!(args)
+ Goodcheck.logger.level = loglevel
+
if args.empty?
targets << Pathname(".")
else
targets.push *args.map {|arg| Pathname(arg) }
end
@@ -67,22 +90,46 @@
else
stderr.puts "Unknown format: #{format}"
return 1
end
- Commands::Check.new(reporter: reporter, config_path: config_path, rules: rules, targets: targets, stderr: stderr).run
+ Goodcheck.logger.info "Configuration = #{config_path}"
+ Goodcheck.logger.info "Rules = [#{rules.join(", ")}]"
+ Goodcheck.logger.info "Format = #{format}"
+ Goodcheck.logger.info "Targets = [#{targets.join(", ")}]"
+ Goodcheck.logger.info "Force download = #{force_download}"
+ Goodcheck.logger.info "Home path = #{home_path}"
+
+ Commands::Check.new(reporter: reporter, config_path: config_path, rules: rules, targets: targets, stderr: stderr, force_download: force_download, home_path: home_path).run
end
def test(args)
config_path = Pathname("goodcheck.yml")
+ loglevel = Logger::ERROR
+ force_download = false
OptionParser.new("Usage: goodcheck test [options]") do |opts|
opts.on("-c CONFIG", "--config=CONFIG") do |config|
config_path = Pathname(config)
end
+ opts.on("-v", "--verbose") do
+ loglevel = Logger::INFO
+ end
+ opts.on("-d", "--debug") do
+ loglevel = Logger::DEBUG
+ end
+ opts.on("--force") do
+ force_download = true
+ end
end.parse!(args)
- Commands::Test.new(stdout: stdout, stderr: stderr, config_path: config_path).run
+ Goodcheck.logger.level = loglevel
+
+ Goodcheck.logger.info "Configuration = #{config_path}"
+ Goodcheck.logger.info "Force download = #{force_download}"
+ Goodcheck.logger.info "Home path = #{home_path}"
+
+ Commands::Test.new(stdout: stdout, stderr: stderr, config_path: config_path, force_download: force_download, home_path: home_path).run
end
def init(args)
config_path = Pathname("goodcheck.yml")
force = false