lib/milestoner/cli/shell.rb in milestoner-15.3.0 vs lib/milestoner/cli/shell.rb in milestoner-16.0.0

- old
+ new

@@ -1,37 +1,40 @@ # frozen_string_literal: true -require "core" +require "sod" module Milestoner module CLI # The main Command Line Interface (CLI) object. class Shell - include Actions::Import[:config, :kernel, :logger, :publish, :status, :specification] + include Import[:defaults_path, :xdg_config, :specification] - def initialize(parser: Parser.new, **) + def initialize(context: Sod::Context, dsl: Sod, **) super(**) - @parser = parser + @context = context + @dsl = dsl end - def call arguments = Core::EMPTY_ARRAY - act_on parser.call(arguments) - rescue OptionParser::ParseError, Error => error - logger.error { error.message } - end + def call(...) = cli.call(...) private - attr_reader :parser + attr_reader :context, :dsl - def act_on configuration - case configuration - in action_config: Symbol => action then config.call action - in action_publish: true then publish.call configuration - in action_status: true then status.call - in action_version: true then kernel.puts specification.labeled_version - else kernel.puts parser.to_s + def cli + context = build_context + + dsl.new :milestoner, banner: specification.banner do + on(Sod::Prefabs::Commands::Config, context:) + on Actions::Publish + on Actions::Status + on(Sod::Prefabs::Actions::Version, context:) + on Sod::Prefabs::Actions::Help, self end + end + + def build_context + context[defaults_path:, xdg_config:, version_label: specification.labeled_version] end end end end