Class: Djin::CLI

Inherits:
Object
  • Object
show all
Extended by:
Dry::CLI::Registry
Defined in:
lib/djin/cli.rb

Defined Under Namespace

Modules: RemoteConfig Classes: File, Version

Class Method Summary collapse

Class Method Details

.load_tasks!(tasks) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/djin/cli.rb', line 7

def self.load_tasks!(tasks)
  tasks.each do |task|
    command = Class.new(Dry::CLI::Command) do
      desc task.description

      define_method(:task) { task }

      def call(**)
        Executor.new.call(task)
      # TODO: Extract error handling output (the same logic is used in djin.rb)
      rescue Djin::TaskError => e
        error_name = e.class.name.split('::').last
        abort("[#{error_name}] #{e.message}")
      end
    end

    register(task.name, command, aliases: task.aliases)
  end
end