Module: Rubyists::Linear::CLI::Caller
- Includes:
- SemanticLogger::Loggable
- Included in:
- Console, Team::List, WhoAmI
- Defined in:
- lib/linear/cli/caller.rb
Overview
This module is prepended to all commands to log their calls
Class Method Summary collapse
-
.prepended(mod) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
Class Method Details
.prepended(mod) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/linear/cli/caller.rb', line 9 def self.prepended(mod) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize # Global options for all commands mod.instance_eval do option :output, type: :string, default: 'text', values: %w[text json], desc: 'Output format' option :debug, type: :integer, aliases: ['-D'], default: 0, desc: 'Debug level (greater than 0 to see backtraces)' end Caller.class_eval do # Wraps the :call method so the debug option is honored, and we can trace the call # as well as handle any exceptions that are raised define_method :call do |**method_args| # rubocop:disable Metrics/AbcSize, Metrics/MethodLength debug = method_args[:debug].to_i Rubyists::Linear.verbosity = debug logger.trace "Calling #{self.class} with #{method_args}" super(**method_args) rescue SmellsBad => e TTY::Prompt.new.error e. TTY::Prompt.new.error '** This smells bad! Bailing. **' exit 22 rescue NotFoundError => e TTY::Prompt.new.error e. TTY::Prompt.new.error '** Record not found, Cannot Continue **' exit 66 rescue StandardError => e TTY::Prompt.new.error "What the heck is this? #{e}" TTY::Prompt.new.error '** WTH? Cannot Continue **' logger.error e.backtrace.join("\n") if debug.positive? exit 88 end end end |