Files
bare-operating-system/packages/bare-os-booter/lib/tools/archive-cli.js
T
2026-08-18 18:11:28 -04:00

65 lines
1.5 KiB
JavaScript

/**
* BSD-style `archive` front-end to the stock ustar `tar` delegate (create/list/extract).
* Maps common `archive c|t|x` invocations to `tar -cf|-tf|-xf`.
*/
import { runTarCli } from './tar-cli.js'
/**
* @param {Record<string, unknown>} ctx
* @param {string[]} argv argv[0] is `archive`
*/
export async function runArchiveCli(ctx, argv) {
const args = argv.slice(1)
if (
!args.length ||
args[0] === '-h' ||
args[0] === '--help' ||
args[0] === 'help'
) {
ctx.console.log(
'usage: archive c ARCHIVE PATH [PATH...]\n' +
' archive t ARCHIVE\n' +
' archive x ARCHIVE\n' +
'Maps to ustar tar -cf / -tf / -xf (see tar --help in handbook).'
)
return
}
const op = args[0]
if (op === 'c') {
const arch = args[1]
const rest = args.slice(2)
if (!arch || !rest.length) {
ctx.console.error('archive c: need ARCHIVE and at least one PATH')
ctx.exitCode = 1
return
}
await runTarCli(ctx, ['tar', '-cf', arch, ...rest])
return
}
if (op === 't') {
const arch = args[1]
if (!arch) {
ctx.console.error('archive t: need ARCHIVE')
ctx.exitCode = 1
return
}
await runTarCli(ctx, ['tar', '-tf', arch])
return
}
if (op === 'x') {
const arch = args[1]
if (!arch) {
ctx.console.error('archive x: need ARCHIVE')
ctx.exitCode = 1
return
}
await runTarCli(ctx, ['tar', '-xf', arch])
return
}
ctx.console.error('archive: first argument must be c, t, or x')
ctx.exitCode = 1
}