lib/tocer/cli/shell.rb in tocer-13.3.1 vs lib/tocer/cli/shell.rb in tocer-14.0.0

- old
+ new

@@ -2,44 +2,33 @@ module Tocer module CLI # The main Command Line Interface (CLI) object. class Shell - ACTIONS = {config: Actions::Config.new, insert: Actions::Insert.new}.freeze + include Actions::Import[:config, :insert, :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 => error puts error.message end private - attr_reader :parser, :actions, :container + attr_reader :parser def perform configuration case configuration - in action_config: Symbol => action then process_config action - in action_insert: true then process_insert configuration + in action_config: Symbol => action then config.call action + in action_insert: true then insert.call configuration in action_version: true then logger.info { specification.labeled_version } - else usage + else logger.any { parser.to_s } end end - - def process_config(action) = actions.fetch(:config).call(action) - - def process_insert(configuration) = actions.fetch(:insert).call(configuration) - - def usage = puts(parser.to_s) - - def specification = container[__method__] - - def logger = container[__method__] end end end