Sha256: 82721b9c85f66ceddb87215f51ee99746265b304d7b5d9d20a5e83ed1014e05f
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require 'vidazing_logger' require 'optparse' require 'ostruct' # Handles command line options for the vidazing_logger binary. # See `vidazing_logger --help` # # @since 0.1.0 class VidazingOptions attr_reader :level, :clean def initialize @level = 'info' @clean = false @options_parser = create_options_parser end def create_options_parser # rubocop:disable Metrics/MethodLength OptionParser.new do |opts| opts.banner = 'Usage: vidazing_logger [options] "Message"' opts.separator '' opts.separator 'Specific options:' level_aliases = { 'd' => 'debug', 'i' => 'info', 'w' => 'warn', 'e' => 'error', 'f' => 'fatal' }.freeze level_list = level_aliases.flatten.join(',') opts.on('-l', '--level LEVEL', level_aliases.values, level_aliases, 'Select log level', " (#{level_list})") do |level| @level = level end opts.on_tail('-c', '--clean', 'Remove the logs/ directory') do @clean = true end end end def parse(args) @options_parser.parse!(args) end end vidazing_options = VidazingOptions.new vidazing_options.parse(ARGV) if vidazing_options.clean puts 'Cleaning the logs/ directory' VidazingLogger.clean end unless ARGV.empty? message = ARGV.join(' ') log = VidazingLogger.logger log.public_send(vidazing_options.level, message) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vidazing_logger-0.2.0 | bin/vidazing_logger |