From 94f156fafb45d13ebf89bae08b98595bbe64d7e4 Mon Sep 17 00:00:00 2001 From: Kien La Date: Sat, 5 Oct 2024 20:12:48 -0400 Subject: [PATCH] add --field option to ls --- src/app_list.ts | 14 ++++++++++---- src/cli.ts | 3 ++- src/stax.ts | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/app_list.ts b/src/app_list.ts index 526e9f4..08d53e3 100644 --- a/src/app_list.ts +++ b/src/app_list.ts @@ -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': '', @@ -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')) diff --git a/src/cli.ts b/src/cli.ts index b88be87..483c717 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -146,7 +146,8 @@ program.command('inspect') program.command('ls') .alias('ps').alias('list') .description('List applications') - .action(() => stax.list()) + .option('-f, --field ', 'Include specified config field', (value, previous) => previous.concat([value]), []) + .action((options) => stax.list({ fields: options.field || [] })) program.command('logs') .argument('', 'Name of application') diff --git a/src/stax.ts b/src/stax.ts index 30a38ad..500a01a 100644 --- a/src/stax.ts +++ b/src/stax.ts @@ -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 }) {