From c11e17573334dfb487a8e1cc25fa84fa9e138f5c Mon Sep 17 00:00:00 2001 From: Lily <129828376+Soccera1@users.noreply.github.com> Date: Tue, 28 Jul 2026 16:12:21 +1000 Subject: Refactor coreutils into single-call command modules (#1) * Refactor to single call --- src/commands/whoami.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/commands/whoami.js (limited to 'src/commands/whoami.js') diff --git a/src/commands/whoami.js b/src/commands/whoami.js new file mode 100644 index 0000000..92b6dd1 --- /dev/null +++ b/src/commands/whoami.js @@ -0,0 +1,20 @@ +#!/usr/bin/env bun + +import { userInfo } from "node:os"; +import { helpVersionOnlyMetaOption, localeQuotedEscapedDiagnostic, normalizeHelpVersionOnlyLongOptions, parseOptions, userNameForUid } from "../shared/common.js"; +import { UsageError, stdout } from "../shared/diagnostics.js"; +import { defineCommand, runAsMain } from "../shared/command.js"; + +export async function whoamiCmd(args) { + args = normalizeHelpVersionOnlyLongOptions(args); + const { operands } = parseOptions(args, { long: { help: false, version: false } }); + if (operands.length) throw new UsageError(`extra operand ${localeQuotedEscapedDiagnostic(operands[0])}`, true); + const info = userInfo(); + stdout(`${await userNameForUid(process.getuid?.() ?? info.uid) ?? info.username}\n`); + return 0; +} + +const singleCall = defineCommand("whoami", whoamiCmd, helpVersionOnlyMetaOption); +export default singleCall; + +if (import.meta.main) await runAsMain(singleCall); -- cgit v1.3