Skip to content

Commit

Permalink
Added CLI command 'log'
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed May 19, 2024
1 parent 6fe7234 commit 5a4ac21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cli/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function (argv) {
default: return helpCreate()
}
case 'delete': return helpDelete()
case 'log': return helpLog()
default: return helpAll()
}
}
Expand All @@ -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()
Expand Down Expand Up @@ -279,3 +281,9 @@ function helpDelete() {
helpPortName()
println()
}

function helpLog() {
println()
println(`Usage: ztm log [<endpoint>]`)
println()
}
20 changes: 19 additions & 1 deletion cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit 5a4ac21

Please sign in to comment.