diff options
| author | Lily <[email protected]> | 2026-07-28 16:12:21 +1000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-07-28 16:12:21 +1000 |
| commit | c11e17573334dfb487a8e1cc25fa84fa9e138f5c (patch) | |
| tree | e91dbd19b524f9432da6bcb86b1fc193e0d02e26 /src/commands/unlink.js | |
| parent | 6a2f098e72e71437154ec00506e8e736aa8e1026 (diff) | |
| download | bnu-c11e17573334dfb487a8e1cc25fa84fa9e138f5c.tar.gz bnu-c11e17573334dfb487a8e1cc25fa84fa9e138f5c.zip | |
Refactor coreutils into single-call command modules (#1)
* Refactor to single call
Diffstat (limited to 'src/commands/unlink.js')
| -rw-r--r-- | src/commands/unlink.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/commands/unlink.js b/src/commands/unlink.js new file mode 100644 index 0000000..9474101 --- /dev/null +++ b/src/commands/unlink.js @@ -0,0 +1,25 @@ +#!/usr/bin/env bun + +import { unlink as fsUnlink } from "node:fs/promises"; +import { helpVersionOnlyMetaOption, localeQuotedEscapedDiagnostic, normalizeHelpVersionOnlyLongOptions, parseOptions, systemErrorMessage } from "../shared/common.js"; +import { UsageError, fail } from "../shared/diagnostics.js"; +import { linkQuotedName } from "../shared/filesystem.js"; +import { defineCommand, runAsMain } from "../shared/command.js"; + +export async function unlinkCmd(args) { + args = normalizeHelpVersionOnlyLongOptions(args); + const { operands } = parseOptions(args, { long: { help: false, version: false } }); + if (!operands.length) throw new UsageError("missing operand", true); + if (operands.length > 1) throw new UsageError(`extra operand ${localeQuotedEscapedDiagnostic(operands[1])}`, true); + try { + await fsUnlink(operands[0]); + } catch (error) { + return fail("unlink", `cannot unlink ${linkQuotedName(operands[0])}: ${systemErrorMessage(error)}`); + } + return 0; +} + +const singleCall = defineCommand("unlink", unlinkCmd, helpVersionOnlyMetaOption); +export default singleCall; + +if (import.meta.main) await runAsMain(singleCall); |
