Class: SchwarmCli::Commands::Templates

Inherits:
Base
  • Object
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

pagination_options

Instance Method Details

#createObject



31
32
33
34
35
36
# File 'lib/schwarm_cli/commands/templates.rb', line 31

def create
  handle_errors do
    data = client.templates.create(name: options[:name], prompt: options[:prompt])
    output_record(data, fields: { "ID" => "id", "Name" => "name" })
  end
end

#delete(id) ⇒ Object



53
54
55
56
57
58
# File 'lib/schwarm_cli/commands/templates.rb', line 53

def delete(id)
  handle_errors do
    client.templates.destroy(id)
    puts "Template #{id} deleted."
  end
end

#listObject



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
# 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", "Prompt" => "prompt", "Created" => "created_at"
                  })
  end
end

#update(id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/schwarm_cli/commands/templates.rb', line 41

def update(id)
  handle_errors do
    attrs = {}
    attrs[:name] = options[:name] if options[:name]
    attrs[:prompt] = options[:prompt] if options[:prompt]

    data = client.templates.update(id, **attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name" })
  end
end