lib/chronicle/etl/cli/main.rb in chronicle-etl-0.4.1 vs lib/chronicle/etl/cli/main.rb in chronicle-etl-0.4.2
- old
+ new
@@ -3,18 +3,29 @@
module Chronicle
module ETL
module CLI
# Main entrypoint for CLI app
class Main < ::Thor
+ class_before :set_log_level
+ class_before :set_color_output
+
+ class_option :log_level, desc: 'Log level (debug, info, warn, error, fatal, silent)', default: 'info'
+ class_option :verbose, aliases: '-v', desc: 'Set log level to verbose', type: :boolean
+ class_option :silent, desc: 'Silence all output', type: :boolean
+ class_option :'no-color', desc: 'Disable colour output', type: :boolean
+
default_task "jobs"
desc 'connectors:COMMAND', 'Connectors available for ETL jobs', hide: true
subcommand 'connectors', Connectors
desc 'jobs:COMMAND', 'Configure and run jobs', hide: true
subcommand 'jobs', Jobs
+ desc 'plugins:COMMAND', 'Configure plugins', hide: true
+ subcommand 'plugins', Plugins
+
# Entrypoint for the CLI
def self.start(given_args = ARGV, config = {})
# take a subcommand:command and splits them so Thor knows how to hand off to the subcommand class
if given_args.any? && given_args[0].include?(':')
commands = given_args.shift.split(':')
@@ -75,9 +86,26 @@
shell.say " $ chronicle-etl --version"
shell.say
shell.say "FULL DOCUMENTATION".bold
shell.say " https://github.com/chronicle-app/chronicle-etl".blue
shell.say
+ end
+ end
+
+ no_commands do
+ def set_color_output
+ String.disable_colorization true if options[:'no-color'] || ENV['NO_COLOR']
+ end
+
+ def set_log_level
+ if options[:silent]
+ Chronicle::ETL::Logger.log_level = Chronicle::ETL::Logger::SILENT
+ elsif options[:verbose]
+ Chronicle::ETL::Logger.log_level = Chronicle::ETL::Logger::DEBUG
+ elsif options[:log_level]
+ level = Chronicle::ETL::Logger.const_get(options[:log_level].upcase)
+ Chronicle::ETL::Logger.log_level = level
+ end
end
end
end
end
end