From 5a4ac216142b69c86a30f483cec85467057da1ba Mon Sep 17 00:00:00 2001 From: pajama-coder Date: Sun, 19 May 2024 11:41:24 +0800 Subject: [PATCH] Added CLI command 'log' --- cli/help.js | 8 ++++++++ cli/main.js | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cli/help.js b/cli/help.js index a8a9c56d..88c180b9 100644 --- a/cli/help.js +++ b/cli/help.js @@ -22,6 +22,7 @@ export default function (argv) { default: return helpCreate() } case 'delete': return helpDelete() + case 'log': return helpLog() default: return helpAll() } } @@ -45,6 +46,7 @@ function helpAll() { println(` describe service | port | endpoint | mesh`) println(` create service | port`) println(` delete service | port`) + println(` log`) println() println(`Object types:`) println() @@ -279,3 +281,9 @@ function helpDelete() { helpPortName() println() } + +function helpLog() { + println() + println(`Usage: ztm log []`) + println() +} diff --git a/cli/main.js b/cli/main.js index 98c9203e..188432b0 100755 --- a/cli/main.js +++ b/cli/main.js @@ -158,7 +158,7 @@ function main() { if (!command || command.startsWith('-')) return errorInput(`missing command`) var f = ({ - help, version, config, + help, version, config, log, start, stop, run, invite, evict, join, leave, get, describe, create, 'delete': deleteCmd, })[command] @@ -863,6 +863,24 @@ function deletePort(argv) { }).catch(error) } +function log(argv) { + var epName = normalizeName(readOptionalWord(argv)) + var opts = parseOptions(optionsGetEP, argv, 'log') + var mesh = null + var c = clients.agent() + selectMesh(c, opts).then(m => { + mesh = m + return selectEndpoint(c, { '--endpoint': epName }, m) + }).then(ep => { + return c.get(`/api/meshes/${mesh.name}/endpoints/${ep.id}/log`) + }).then(ret => { + JSON.decode(ret).forEach(l => { + println(l.time, l.message) + }) + pipy.exit(0) + }).catch(error) +} + // // Utilities //