Class: Textus::CLI::Extensions

Inherits:
Verb
  • Object
show all
Includes:
DeprecatedAliasMixin
Defined in:
lib/textus/cli/extensions.rb

Instance Attribute Summary

Attributes included from DeprecatedAliasMixin

#deprecated_alias

Attributes inherited from Verb

#positional

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DeprecatedAliasMixin

prepended

Methods inherited from Verb

#emit, inherited, #initialize, needs_store?, option, options, #parse

Constructor Details

This class inherits a constructor from Textus::CLI::Verb

Class Method Details

.deprecated_nameObject



6
# File 'lib/textus/cli/extensions.rb', line 6

def self.deprecated_name = "extensions"

.replacement_pathObject



7
# File 'lib/textus/cli/extensions.rb', line 7

def self.replacement_path = "extension list"

Instance Method Details

#call(store) ⇒ Object

rubocop:disable Metrics/AbcSize



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/textus/cli/extensions.rb', line 11

def call(store) # rubocop:disable Metrics/AbcSize
  # When invoked as the flat alias `textus extensions list`, the positional "list"
  # is still present. When invoked via `textus extension list` (group), it has been
  # consumed by the group dispatcher — both are valid.
  subcommand = positional.first
  if subcommand
    raise UsageError.new("extensions requires 'list'") unless subcommand == "list"

    positional.shift
  end

  rows = []
  rows += store.registry.action_names.map { |n| { "kind" => "action", "name" => n.to_s } }
  rows += store.registry.doctor_check_names.map { |n| { "kind" => "doctor_check", "name" => n.to_s } }
  rows += store.registry.reducer_names.map { |n| { "kind" => "reducer", "name" => n.to_s } }
  store.registry.hook_events.each do |evt|
    store.registry.hooks(evt).each do |h|
      rows << { "kind" => "hook", "event" => evt.to_s, "name" => h[:name].to_s }
    end
  end
  store.manifest.entries.each do |e|
    e.events.each do |evt, defs|
      Array(defs).each do |defn|
        next unless defn["exec"]

        rows << {
          "kind" => "hook", "event" => evt.to_s, "exec" => defn["exec"],
          "key" => e.key, "as" => defn["as"] || "script"
        }
      end
    end
  end
  rows.select! { |r| r["kind"] == kind } if kind

  emit({ "extensions" => rows })
end