Class: SchwarmCli::Commands::AgentSubscriptions

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

Constant Summary

Constants inherited from Base

Base::DEFAULT_LIST_LIMIT

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?, pagination_options

Instance Method Details

#createObject



43
44
45
46
47
48
# File 'lib/schwarm_cli/commands/agent_subscriptions.rb', line 43

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

#delete(id) ⇒ Object



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

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

#listObject



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

def list
  handle_errors do
    data = fetch_paged do |page_params|
      client.subscriptions.list(repository_id: resolve_repo(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



80
81
82
83
84
85
# File 'lib/schwarm_cli/commands/agent_subscriptions.rb', line 80

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

#show(id) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/schwarm_cli/commands/agent_subscriptions.rb', line 22

def show(id)
  handle_errors do
    data = client.subscriptions.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Name" => "name", "Repository" => "github_repository_name",
                    "Agent" => "shared_agent_id", "Enabled" => "enabled",
                    "Schedule" => "schedule",
                    "Additional Instructions" => "additional_instructions",
                    "Created" => "created_at", "Updated" => "updated_at"
                  })
  end
end

#toggle(id) ⇒ Object



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

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

#update(id) ⇒ Object



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

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