Class: SchwarmCli::Commands::Templates

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/templates.rb

Instance Method Summary collapse

Instance Method Details

#createObject



28
29
30
31
32
33
# File 'lib/schwarm_cli/commands/templates.rb', line 28

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



50
51
52
53
54
55
# File 'lib/schwarm_cli/commands/templates.rb', line 50

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

#listObject



8
9
10
11
12
13
# File 'lib/schwarm_cli/commands/templates.rb', line 8

def list
  handle_errors do
    data = client.templates.list(query: options[:query])
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[CREATED created_at]])
  end
end

#show(id) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/schwarm_cli/commands/templates.rb', line 16

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



38
39
40
41
42
43
44
45
46
47
# File 'lib/schwarm_cli/commands/templates.rb', line 38

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