lib/pennyworth/cli/shell.rb in pennyworth-12.3.1 vs lib/pennyworth/cli/shell.rb in pennyworth-13.0.0

- old
+ new

@@ -2,82 +2,53 @@ module Pennyworth module CLI # The main Command Line Interface (CLI) object. class Shell - ACTIONS = { - config: Actions::Config.new, - encodings: Actions::Encodings.new, - git_hub: Actions::GitHub.new, - http_statuses: Actions::HTTPStatuses.new, - ruby_gems: Actions::RubyGems.new, - system_errors: Actions::System::Errors.new, - system_signals: Actions::System::Signals.new, - text: Actions::Text.new - }.freeze + include Actions::Import[ + :config, + :encodings, + :git_hub, + :http_statuses, + :ruby_gems, + :system_errors, + :system_signals, + :text, + :specification, + :logger + ] - def initialize parser: Parser.new, actions: ACTIONS, container: Container + def initialize parser: Parser.new, **dependencies + super(**dependencies) @parser = parser - @actions = actions - @container = container end def call arguments = [] perform parser.call(arguments) rescue OptionParser::ParseError, KeyError => error logger.error { error.message } end private - attr_reader :parser, :actions, :container + attr_reader :parser - # rubocop:disable Metrics/MethodLength def perform configuration case configuration - in action_config: Symbol => action then config action - in action_encodings: true then encodings - in action_git_hub: :organization then git_hub_organization configuration - in action_git_hub: :user then git_hub_user configuration - in action_http_statuses: true then http_statuses - in action_ruby_gems: true then ruby_gems configuration - in action_system_signals: true then system_signals - in action_system_errors: true then system_errors - in action_text: String => content then text content + in action_config: Symbol => action then config.call action + in action_encodings: true then encodings.call + in action_git_hub: :organization + git_hub.call "orgs/#{configuration.git_hub_organization}/repos" + in action_git_hub: :user then git_hub.call "users/#{configuration.git_hub_user}/repos" + in action_http_statuses: true then http_statuses.call + in action_ruby_gems: true + ruby_gems.call "owners/#{configuration.ruby_gems_owner}/gems.json" + in action_system_signals: true then system_signals.call + in action_system_errors: true then system_errors.call + in action_text: String => content then text.call content in action_version: true then logger.info { specification.labeled_version } - else usage + else logger.any { parser.to_s } end end - # rubocop:enable Metrics/MethodLength - - def config(action) = actions.fetch(__method__).call(action) - - def encodings = actions.fetch(__method__).call - - def git_hub_organization configuration - actions.fetch(:git_hub).call("orgs/#{configuration.git_hub_organization}/repos") - end - - def git_hub_user configuration - actions.fetch(:git_hub).call("users/#{configuration.git_hub_user}/repos") - end - - def http_statuses = actions.fetch(__method__).call - - def ruby_gems configuration - actions.fetch(__method__).call("owners/#{configuration.ruby_gems_owner}/gems.json") - end - - def system_errors = actions.fetch(__method__).call - - def system_signals = actions.fetch(__method__).call - - def text(content) = actions.fetch(__method__).call(content) - - def usage = logger.unknown { parser.to_s } - - def specification = container[__method__] - - def logger = container[__method__] end end end