Class: SchwarmCli::Commands::Templates
- Inherits:
-
Base
- Object
- Thor
- Base
- SchwarmCli::Commands::Templates
show all
- Defined in:
- lib/schwarm_cli/commands/templates.rb
Constant Summary
Constants inherited
from Base
Base::DEFAULT_LIST_LIMIT
Instance Method Summary
collapse
Methods inherited from Base
exit_on_failure?, pagination_options
Instance Method Details
#create ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/schwarm_cli/commands/templates.rb', line 33
def create
handle_errors do
attrs = { name: options[:name], prompt_prefix: options[:prompt] }
attrs[:description] = options[:description] if options[:description]
data = client.templates.create(**attrs)
output_record(data, fields: { "ID" => "id", "Name" => "name" })
end
end
|
#delete(id) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/schwarm_cli/commands/templates.rb', line 55
def delete(id)
handle_errors do
client.templates.destroy(id)
puts "Template #{id} deleted."
end
end
|
#list ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/schwarm_cli/commands/templates.rb', line 9
def list
handle_errors do
data = fetch_paged do |page_params|
client.templates.list(query: options[:query], **page_params)
end
output_list(data, columns: [%w[ID id], %w[NAME name], %w[CREATED created_at]])
end
end
|
#show(id) ⇒ Object
19
20
21
22
23
24
25
26
27
|
# File 'lib/schwarm_cli/commands/templates.rb', line 19
def show(id)
handle_errors do
data = client.templates.find(id)
output_record(data, fields: {
"ID" => "id", "Name" => "name", "Description" => "description",
"Prompt" => "prompt_prefix", "Created" => "created_at"
})
end
end
|
#update(id) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/schwarm_cli/commands/templates.rb', line 47
def update(id)
handle_errors do
data = client.templates.update(id, **update_attrs)
output_record(data, fields: { "ID" => "id", "Name" => "name" })
end
end
|