Class: SchwarmCli::Commands::SharedAgentsCmd

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

Instance Method Summary collapse

Instance Method Details

#createObject



32
33
34
35
36
37
38
39
40
# File 'lib/schwarm_cli/commands/shared_agents.rb', line 32

def create
  handle_errors do
    attrs = { name: options[:name], prompt: options[:prompt] }
    attrs[:schedule] = options[:schedule] if options[:schedule]

    data = client.shared_agents.create(**attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Enabled" => "enabled" })
  end
end

#delete(id) ⇒ Object



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

def delete(id)
  handle_errors do
    client.shared_agents.destroy(id)
    puts "Shared agent #{id} deleted."
  end
end

#listObject



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

def list
  handle_errors do
    data = client.shared_agents.list(query: options[:query])
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[ENABLED enabled],
                                %w[SCHEDULE schedule]])
  end
end

#show(id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/schwarm_cli/commands/shared_agents.rb', line 17

def show(id)
  handle_errors do
    data = client.shared_agents.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Name" => "name", "Enabled" => "enabled",
                    "Schedule" => "schedule", "Prompt" => "prompt",
                    "Created" => "created_at", "Updated" => "updated_at"
                  })
  end
end

#toggle(id) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/schwarm_cli/commands/shared_agents.rb', line 62

def toggle(id)
  handle_errors do
    data = client.shared_agents.toggle(id)
    status = data.dig("data", "enabled") ? "enabled" : "disabled"
    puts "Shared agent #{id} #{status}."
  end
end

#update(id) ⇒ Object



46
47
48
49
50
51
# File 'lib/schwarm_cli/commands/shared_agents.rb', line 46

def update(id)
  handle_errors do
    data = client.shared_agents.update(id, **update_attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Enabled" => "enabled" })
  end
end