diff options
| author | Soccera1 <[email protected]> | 2026-07-18 09:27:17 +1000 |
|---|---|---|
| committer | Soccera1 <[email protected]> | 2026-07-18 09:27:17 +1000 |
| commit | 6f5241afb5bd1d6a1a8724bf06cc6f205c279402 (patch) | |
| tree | 2aa852e968f6b89f2c8458333ce3e7c38b3c2450 /src/commands/whoami.js | |
| parent | a753f669c9bedfccb9f7f400da018bb487dca5d0 (diff) | |
| download | bnu-6f5241afb5bd1d6a1a8724bf06cc6f205c279402.tar.gz bnu-6f5241afb5bd1d6a1a8724bf06cc6f205c279402.zip | |
Refactor to single call
Diffstat (limited to 'src/commands/whoami.js')
| -rw-r--r-- | src/commands/whoami.js | 20 |
1 files changed, 20 insertions, 0 deletions
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); |
