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, Base::INHERITED_OPTIONS

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, pagination_options

Instance Method Details

#createObject



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

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

    data = client.agents.create(**attrs)
    output_record(data, fields: agent_fields)
  end
end

#delete(id) ⇒ Object



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

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

#listObject



14
15
16
17
18
19
20
21
22
# File 'lib/schwarm_cli/commands/agents.rb', line 14

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

#show(id) ⇒ Object



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

def show(id)
  handle_errors do
    data = client.agents.find(id)
    output_record(data, fields: agent_fields)
  end
end

#toggle(id) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/schwarm_cli/commands/agents.rb', line 70

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



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

def update(id)
  handle_errors do
    data = client.agents.update(id, **update_attrs)
    output_record(data, fields: agent_fields)
  end
end