Skip to content

Commit

Permalink
add --field option to ls
Browse files Browse the repository at this point in the history
  • Loading branch information
kla committed Oct 6, 2024
1 parent 216ff83 commit 94f156f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/app_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ function name(app: App, container: Container) {
return app.name
}

export default function list(apps: App[]) {
export default function list(apps: App[], options: { fields?: string[] } = {}) {
const head = ['', 'App', 'Status', 'Uptime', 'Forwarding', 'Source'].concat(options.fields || [])
const table = new Table({
head: ['', 'App', 'Status', 'Uptime', 'Forwarding', 'Source'],
head: head,
style: { head: ['cyan'] },
chars: {
'top': '', 'top-mid': '', 'top-left': '', 'top-right': '',
Expand All @@ -31,14 +32,19 @@ export default function list(apps: App[]) {
table.push([ icons[app.state], app.name, '', '', '', source ])

app.containers.forEach((container) => {
table.push([
const items = [
icons[container.state] || icons.unknown,
name(app, container),
container.state,
container.uptime?.replace(' ago', ''),
container.forwardedPorts.join(', '),
app.containers.length == 1 ? source : '',
])
]

if (options.fields?.length)
options.fields.forEach(field => items.push(container.config.fetch(field)))

table.push(items)
})
})
console.log(table.toString().replaceAll('\n *\n', '\n'))
Expand Down
3 changes: 2 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ program.command('inspect')
program.command('ls')
.alias('ps').alias('list')
.description('List applications')
.action(() => stax.list())
.option('-f, --field <name>', 'Include specified config field', (value, previous) => previous.concat([value]), [])
.action((options) => stax.list({ fields: options.field || [] }))

program.command('logs')
.argument('<name>', 'Name of application')
Expand Down
4 changes: 2 additions & 2 deletions src/stax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default class Stax {
this.context = context
}

list() {
list(this.apps())
list(options: { fields?: string[] } = {}) {
list(this.apps(), options)
}

async setup(config: StaxConfig, options: { inspect?: boolean } = { inspect: false }) {
Expand Down

0 comments on commit 94f156f

Please sign in to comment.