lib/tocer/cli/shell.rb in tocer-12.2.0 vs lib/tocer/cli/shell.rb in tocer-13.0.0
- old
+ new
@@ -2,42 +2,38 @@
module Tocer
module CLI
# The main Command Line Interface (CLI) object.
class Shell
- PROCESSORS = {config: Processors::Config.new, build: Processors::Build.new}.freeze
+ ACTIONS = {config: Actions::Config.new, insert: Actions::Insert.new}.freeze
- def initialize parser: Parsers::Assembler.new, processors: PROCESSORS
+ def initialize parser: Parser.new, actions: ACTIONS
@parser = parser
- @processors = processors
+ @actions = actions
end
def call arguments = []
- parse arguments
-
- case options
- in config: action then process_config action
- in build: path then process_build path
- in version: then puts version
- else usage
- end
+ perform parser.call(arguments)
+ rescue OptionParser::ParseError => error
+ puts error.message
end
private
- attr_reader :parser, :processors
+ attr_reader :parser, :actions
- def parse arguments = []
- parser.call arguments
- rescue StandardError => error
- puts error.message
+ def perform configuration
+ case configuration
+ in action_config: Symbol => action then process_config action
+ in action_insert: true then process_insert configuration
+ in action_version: true then puts Identity::VERSION_LABEL
+ else usage
+ end
end
- def process_config(action) = processors.fetch(:config).call(action)
+ def process_config(action) = actions.fetch(:config).call(action)
- def process_build(path) = processors.fetch(:build).call(path, options)
-
- def options = parser.to_h
+ def process_insert(configuration) = actions.fetch(:insert).call(configuration)
def usage = puts(parser.to_s)
end
end
end