lib/tocer/cli/shell.rb in tocer-15.2.0 vs lib/tocer/cli/shell.rb in tocer-16.0.0
- old
+ new
@@ -1,36 +1,39 @@
# frozen_string_literal: true
-require "core"
+require "sod"
module Tocer
module CLI
# The main Command Line Interface (CLI) object.
class Shell
- include Actions::Import[:config, :insert, :kernel, :logger, :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
- 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_insert: true then insert.call configuration
- in action_version: true then kernel.puts specification.labeled_version
- else kernel.puts parser.to_s
+ def cli
+ context = build_context
+
+ dsl.new :tocer, banner: specification.banner do
+ on(Sod::Prefabs::Commands::Config, context:)
+ on Commands::Upsert
+ 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