Class: SchwarmCli::Commands::Agents

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/agents.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



37
38
39
40
41
42
43
44
45
# File 'lib/schwarm_cli/commands/agents.rb', line 37

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



59
60
61
62
63
64
# File 'lib/schwarm_cli/commands/agents.rb', line 59

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

#listObject



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

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

#run_now(id) ⇒ Object



77
78
79
80
81
82
# File 'lib/schwarm_cli/commands/agents.rb', line 77

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

#show(id) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/schwarm_cli/commands/agents.rb', line 21

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



67
68
69
70
71
72
73
# File 'lib/schwarm_cli/commands/agents.rb', line 67

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



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

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