Class: SchwarmCli::Commands::Agents

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

Instance Method Summary collapse

Instance Method Details

#createObject



34
35
36
37
38
39
40
41
42
# File 'lib/schwarm_cli/commands/agents.rb', line 34

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

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

#delete(id) ⇒ Object



56
57
58
59
60
61
# File 'lib/schwarm_cli/commands/agents.rb', line 56

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

#listObject



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

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

#run_now(id) ⇒ Object



74
75
76
77
78
79
# File 'lib/schwarm_cli/commands/agents.rb', line 74

def run_now(id)
  handle_errors do
    client.agents.run_now(id)
    puts "Agent #{id} triggered."
  end
end

#show(id) ⇒ Object



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

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

#toggle(id) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/schwarm_cli/commands/agents.rb', line 64

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

#update(id) ⇒ Object



48
49
50
51
52
53
# File 'lib/schwarm_cli/commands/agents.rb', line 48

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