#!/usr/bin/env ruby require 'bundler/setup' require 'flows' require 'pry' require 'gli' require 'rainbow/refinement' using Rainbow require_relative 'errors_cli/contract_error_demo' require_relative 'errors_cli/flows_router_error_demo' require_relative 'errors_cli/di_error_demo' require_relative 'errors_cli/oc_error_demo' require_relative 'errors_cli/railway_error_demo' require_relative 'errors_cli/result_error_demo' require_relative 'errors_cli/scp_error_demo' require_relative 'errors_cli/flow_error_demo' class ErrorsCLI extend GLI::App program_desc 'Error reporting demo' use_openstruct true def self.make_cmd(ctx, title, name) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength ctx.desc title ctx.command name do |cmd| cmd.action do |_, _, _| puts title.green puts(('BEGIN' + '-' * (title.length - 5)).color(:darkgray)) yield rescue StandardError => err puts err.message puts(('END' + '-' * (title.length - 3)).color(:darkgray)) puts end end end make_cmd self, 'Flows::Contract error', :contract do ContractErrorDemo.call end make_cmd self, 'Flows::Flow::Router::NoRouteError', :router do FlowsRouterErrorDemo.call end desc 'Flows::Plugin::DependencyInjector errors' command :di do |cmd| make_cmd cmd, 'Missing Dependency', :missing do DIErrorDemo.missing_dependency end make_cmd cmd, 'Unexpected Dependency', :unexpected do DIErrorDemo.unexpected_dependency end make_cmd cmd, 'Invalid Type', :invalid_type do DIErrorDemo.invalid_type_dependency end make_cmd cmd, 'Missing Default', :missing_default do DIErrorDemo.missing_default end end desc 'OutputContract plugin errors' command :output_contract do |cmd| make_cmd cmd, 'No Contract error', :no_contract do OCErrorDemo.no_contract end make_cmd cmd, 'Contract error', :contract do OCErrorDemo.contract_error end make_cmd cmd, 'Status error', :status do OCErrorDemo.status_error end make_cmd cmd, 'Result type error', :result_type do OCErrorDemo.result_type_error end end desc 'Railway errors' command :railway do |cmd| make_cmd cmd, 'No Steps error', :no_steps do RailwayErrorDemo.call end end desc 'Result errors' command :result do |cmd| make_cmd cmd, 'Access error for successful result', :ok_access do ResultErrorDemo.success_access_error end make_cmd cmd, 'Access error for failure result', :err_access do ResultErrorDemo.failure_access_error end end desc 'Shared Context Pipeline errors' command :scp do |cmd| make_cmd cmd, 'No Steps error', :no_steps do SCPErrorDemo.no_steps end make_cmd cmd, 'Missing Step Implementation error', :no_step_impl do SCPErrorDemo.no_step_impl end end desc 'Flow errors' command :flow do |cmd| make_cmd cmd, 'No first node', :no_first_node do FlowErrorDemo.no_first_node end make_cmd cmd, 'Invalid Node route', :invalid_node_route do FlowErrorDemo.invalid_node_route end end end exit ErrorsCLI.run(ARGV)