diff --git a/README.md b/README.md index 2429fcc..07aa316 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ Supervisor.stack_stats(stack_uuid) # Retrieves statistics for a sta Supervisor.update_stack(stack_uuid, params) # Updates an existing stack Supervisor.delete_stack(stack_uuid) # Deletes a specified stack Supervisor.control_stack(stack_uuid, command) # Controls (start, stop) a stack +Supervisore.stack_last_log_entry(stack_uuid) # Retrieves the last log entry for a stack +Supervisor.stack_logs(stack_uuid) { block } # Retrieves logs for a stack (Server-sent events) Supervisor.health_check # Checks the health of the service ``` @@ -105,6 +107,8 @@ supervisor stacks [options] | `show` | Shows details of a specified stack. | | `stats` | Retrieves statistics for a stack. | | `list` | Lists all stacks in Supervisor. | +| `control` | Controls (start, stop, rest) a stack. | +| `log` | Retrieves log for a stack. | #### Subcommand Options diff --git a/etc/bash/completion b/etc/bash/completion index 86fb43a..194f4fc 100644 --- a/etc/bash/completion +++ b/etc/bash/completion @@ -185,7 +185,7 @@ _supervisor_stack_control() { __supervisor_stacks_completion } -_supervisor_stack_logs() { +_supervisor_stack_log() { local cur prev words _get_comp_words_by_ref -n : cur prev words @@ -209,7 +209,7 @@ _supervisor_stacks() { local cur prev words _get_comp_words_by_ref -n : cur prev words - local actions="create delete list show stats update control logs" + local actions="create delete list show stats update control log" local word for word in "${words[@]}"; do @@ -242,8 +242,8 @@ _supervisor_stacks() { _supervisor_stack_control return ;; - logs) - _supervisor_stack_logs + log) + _supervisor_stack_log return ;; esac diff --git a/lib/supervisor/app.rb b/lib/supervisor/app.rb index 50ba85a..5da44d0 100644 --- a/lib/supervisor/app.rb +++ b/lib/supervisor/app.rb @@ -9,7 +9,7 @@ require_relative 'app/stacks/stats' require_relative 'app/stacks/update' require_relative 'app/stacks/control' -require_relative 'app/stacks/logs' +require_relative 'app/stacks/log' module Supervisor module App @@ -25,7 +25,7 @@ class Command < Supervisor::App::BaseCommand subcommand 'update', 'Update a stack', Supervisor::App::Stacks::UpdateCommand subcommand 'delete', 'Delete a stack', Supervisor::App::Stacks::DeleteCommand subcommand 'control', 'Control a stack', Supervisor::App::Stacks::ControlCommand - subcommand 'logs', 'Show the logs of a stack', Supervisor::App::Stacks::LogsCommand + subcommand 'log', 'Show the log of a stack', Supervisor::App::Stacks::LogCommand end end end diff --git a/lib/supervisor/app/stacks/logs.rb b/lib/supervisor/app/stacks/log.rb similarity index 90% rename from lib/supervisor/app/stacks/logs.rb rename to lib/supervisor/app/stacks/log.rb index aa73b69..55791b0 100644 --- a/lib/supervisor/app/stacks/logs.rb +++ b/lib/supervisor/app/stacks/log.rb @@ -5,7 +5,7 @@ module Supervisor module App module Stacks - class LogsCommand < BaseCommand + class LogCommand < BaseCommand parameter 'STACK_UUID', 'the UUID of the stack' option ['--follow'], :flag, 'follow the log output' option ['--json'], :flag, 'output as JSON' @@ -19,7 +19,7 @@ def execute end end - log = call(:stack_last_logs_entry, stack_uuid) + log = call(:stack_last_log_entry, stack_uuid) puts table(log) end @@ -27,7 +27,7 @@ def execute def stream configure - Supervisor.stack_logs(stack_uuid) do |chunk| + Supervisor.stack_log(stack_uuid) do |chunk| regexp = Regexp.new('data: (?.*)\n', Regexp::MULTILINE) match = regexp.match(chunk) diff --git a/lib/supervisor/client.rb b/lib/supervisor/client.rb index e926758..47dc2b8 100644 --- a/lib/supervisor/client.rb +++ b/lib/supervisor/client.rb @@ -49,16 +49,16 @@ def control_stack(stack_uuid, command) true end - def stack_last_logs_entry(stack_uuid) - request(:get, "/stacks/#{stack_uuid}/last_logs_entry") + def stack_last_log_entry(stack_uuid) + request(:get, "/stacks/#{stack_uuid}/log") end - def stack_logs(stack_uuid, read_timeout: 3600, &) - path = "/stacks/#{stack_uuid}/logs" + def stack_log(stack_uuid, read_timeout: 3600, &) + path = "/stacks/#{stack_uuid}/log" headers = { Authorization: "Bearer #{@api_key}" } begin - response = self.class.get("#{@base_uri}#{path}", headers:, stream_body: true, read_timeout:, &) + response = self.class.get("#{@base_uri}#{path}?follow=true", headers:, stream_body: true, read_timeout:, &) rescue StandardError => e raise Supervisor::Error, e.message end