Class: Textus::CLI::Action
Instance Attribute Summary
#deprecated_alias
Attributes inherited from Verb
#positional
Class Method Summary
collapse
Instance Method Summary
collapse
prepended
Methods inherited from Verb
#emit, inherited, #initialize, needs_store?, option, options
Class Method Details
.deprecated_name ⇒ Object
6
|
# File 'lib/textus/cli/action.rb', line 6
def self.deprecated_name = "action"
|
.replacement_path ⇒ Object
7
|
# File 'lib/textus/cli/action.rb', line 7
def self.replacement_path = "extension run"
|
Instance Method Details
#call(store) ⇒ Object
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
47
48
|
# File 'lib/textus/cli/action.rb', line 13
def call(store)
name = @raw_argv.shift
raise UsageError.new("action requires a name") if name.nil?
as_flag = nil
args = {}
@raw_argv.each do |tok|
case tok
when /\A--as=(.+)\z/ then as_flag = ::Regexp.last_match(1)
when /\A--format=/ then next
when /\A--([\w-]+)=(.*)\z/ then args[::Regexp.last_match(1)] = ::Regexp.last_match(2)
else
raise UsageError.new("unknown arg to 'action #{name}': #{tok}")
end
end
role = Role.resolve(flag: as_flag, env: ENV, root: store.root)
callable = store.registry.action(name)
view = StoreView.new(store, writable: true, as: role)
begin
Timeout.timeout(Textus::Refresh::ACTION_TIMEOUT_SECONDS) do
callable.call(config: {}, store: view, args: args)
end
rescue Timeout::Error
raise UsageError.new(
"action '#{name}' exceeded #{Textus::Refresh::ACTION_TIMEOUT_SECONDS}s timeout",
)
rescue Textus::Error
raise
rescue StandardError => e
raise UsageError.new("action '#{name}' raised: #{e.class}: #{e.message}")
end
emit({ "action" => name, "ok" => true })
end
|
#parse(argv) ⇒ Object
9
10
11
|
# File 'lib/textus/cli/action.rb', line 9
def parse(argv)
@raw_argv = argv
end
|