Sha256: 1d5482c031cd6aba758178d128db76967c8e0887ff9ce0b54d3cdde8a6a5e654
Contents?: true
Size: 1.28 KB
Versions: 8
Compression:
Stored size: 1.28 KB
Contents
require 'clamp' require 'xcres/logger' # Base class for commands # class XCRes::Command < Clamp::Command option ['--silent'], :flag, 'Show nothing' option ['--[no-]ansi'], :flag, 'Show output without ANSI codes', default: true option ['-v', '--verbose'], :flag, 'Show more debugging information' # Run the command, with the specified arguments. # # This calls {#parse} to process the command-line arguments, # then delegates to {#execute}. # # @param [Array<String>] arguments command-line arguments # def run(arguments) super rescue Clamp::HelpWanted => e raise e # Clamp will handle this for us rescue StandardError => error fail error exit 1 end def execute # Configure logger configure_logger end #----------------------------------------------------------------------------# # @!group Logger # Lazy-instantiate a logger # def logger @logger ||= XCRes::Logger.new end # Delegate log level methods to the logger # delegate :inform, :log, :success, :warn, :fail, to: :logger # Checks the configured option to configure the logger # def configure_logger logger.silent = silent? logger.colored = ansi? if verbose? logger.verbose = verbose? log 'Verbose mode is enabled.' end end end
Version data entries
8 entries across 8 versions & 1 rubygems