bin.ts
This file
Path
apps/cli/src/bin.ts
44 lines · 1.7 KiB · TypeScript
Last changed by
Fit W4 group A together on main: every CLI test runs signed out, the binary runs on the real client, usage errors exit 2 as typed failures, and the heaviest tests get a hang limitoscabrielbefore adoptionb08d5f6
History of this fileTake it
The walk stopped after 200 commits: lines older than 878da37 point at it.
Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37
lines 1–3why, one step back1#!/usr/bin/env node2/**3 * The CLI's process entry: `program` over the arguments the process wasFit W4 group A together on main: every CLI test runs signed out, the binary runs on the real client, usage errors exit 2 as typed failures, and the heaviest tests get a hang limitoscabrielbefore adoptionb08d5f6
lines 4–5why, one step back4 * started with, on Bun's services and `CliServices` (the credentials file,5 * the invocation policy, output in its form and the remote client).Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37
lines 6–14why, one step back6 * Tests never import this file; they run `program` with their own services,7 * and `test/build.test.ts` runs what `build.ts` makes of it. One file plays8 * two roles, chosen by the name it was started by: the CLI, and git's9 * credential helper.10 */11import { BunRuntime, BunServices } from "@effect/platform-bun";12import { Brand } from "@repo/brand";13import { Effect, Layer, Path, Stdio } from "effect";14Fit W4 group A together on main: every CLI test runs signed out, the binary runs on the real client, usage errors exit 2 as typed failures, and the heaviest tests get a hang limitoscabrielbefore adoptionb08d5f6
line 15why, one step back15import { CliServices, program } from "./main.ts";Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37
line 16why, one step back16Fit W4 group A together on main: every CLI test runs signed out, the binary runs on the real client, usage errors exit 2 as typed failures, and the heaviest tests get a hang limitoscabrielbefore adoptionb08d5f6
line 17why, one step back17const live = CliServices.pipe(Layer.provideMerge(BunServices.layer));Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37
lines 18–44why, one step back1819/**20 * The names this process may have been started by. The compiled binary21 * keeps the name of the link it was run through in `argv0` (its `argv[1]`22 * is its own bundled path); Node or Bun running `dist/bin.js` through an23 * npm bin link keeps the link's path in `argv[1]` (their `argv0` is the24 * runtime's).25 */26const startedAs = Effect.map(Path.Path, (path) =>27 [process.argv0, process.argv[1]].map((name) => path.basename(name ?? ""))28);2930/**31 * Run as `git-credential-<slug>`, the process is `<cli> credential` with32 * git's arguments (`get`, `store` or `erase`); run by any other name, it is33 * the CLI.34 */35const main = Effect.gen(function* () {36 const names = yield* startedAs;37 const args = yield* Effect.flatMap(Stdio.Stdio, (stdio) => stdio.args);3839 return yield* program(40 names.includes(Brand.gitCredentialHelper) ? ["credential", ...args] : args41 );42});4344BunRuntime.runMain(main.pipe(Effect.provide(live)));