Class: Textus::CLI::Runner::Base

Inherits:
Verb
  • Object
show all
Defined in:
lib/textus/cli/runner.rb

Overview

Subclassable base for contract-projected verbs. Carries the verb’s contract (class attr ‘spec`) and the generic dispatch, exposing one overridable seam, #invoke, that defaults to the generic projection. Escape-hatch verbs subclass this and override #invoke to add behavior (suggestions, –stdin, BuildLock, multi-dispatch) WITHOUT restating the verb name — `spec.verb` remains the single source of dispatch.

Direct Known Subclasses

Verb::Build, Verb::Get, Verb::Put

Class Attribute Summary collapse

Attributes inherited from Verb

#positional, #stdin

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Verb

#context_for, descendants, #emit, inherited, #initialize, needs_store?, option, options, parent_group, #parse, #resolved_role, #session_for

Constructor Details

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

Class Attribute Details

.specObject

Returns the value of attribute spec.



15
16
17
# File 'lib/textus/cli/runner.rb', line 15

def spec
  @spec
end

Class Method Details

.command_name(name = nil) ⇒ Object

ADR 0064: derive the CLI command name from the contract’s cli_leaf when not set explicitly, so an escape-hatch class never restates its own name. The reconciliation spec proves command_name == cli_leaf for every such class, so this is an equivalence, not a behavior change.



21
22
23
24
25
# File 'lib/textus/cli/runner.rb', line 21

def command_name(name = nil)
  return super if name

  super() || spec&.cli_leaf
end

Instance Method Details

#call(store) ⇒ Object



30
31
32
# File 'lib/textus/cli/runner.rb', line 30

def call(store)
  invoke(store)
end

#flag_values(s = spec) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/textus/cli/runner.rb', line 39

def flag_values(s = spec)
  s.args.reject(&:positional).each_with_object({}) do |a, h|
    raw = respond_to?(a.name) ? public_send(a.name) : nil
    next if raw.nil?

    h[a.name] = Runner.coerce(a, raw)
  end
end

#invoke(store) ⇒ Object

Default: pure contract projection. Override in subclasses for behavior.



35
36
37
# File 'lib/textus/cli/runner.rb', line 35

def invoke(store)
  Runner.dispatch(self, store, spec)
end

#specObject



28
# File 'lib/textus/cli/runner.rb', line 28

def spec = self.class.spec