Class: Textus::CLI::Verb::Put

Inherits:
Runner::Base show all
Defined in:
lib/textus/cli/verb/put.rb

Instance Attribute Summary

Attributes inherited from Textus::CLI::Verb

#positional, #stdin

Instance Method Summary collapse

Methods inherited from Runner::Base

#call, command_name, #flag_values, #spec

Methods inherited from Textus::CLI::Verb

command_name, #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

Instance Method Details

#invoke(store) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/textus/cli/verb/put.rb', line 10

def invoke(store)
  key = positional.shift or raise UsageError.new("put requires a key")
  raise UsageError.new("put requires --stdin in v1") unless use_stdin

  role = resolved_role(store)

  # put only stores the stdin JSON (ADR 0089): no transform-on-write.
  # Ingest (running a handler over bytes) is system-pushed via reconcile
  # and hook run, never a put flag.
  payload = JSON.parse(@stdin.read)

  meta = payload["_meta"] || {}
  body = payload["body"] || ""
  if_etag = payload["if_etag"]
  result = store.as(role).put(key, meta: meta, body: body, if_etag: if_etag)
  emit(result.to_h_for_wire)
end