From 48db351b51a74f634779b453f299376a526da911 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 1 Dec 2023 09:17:28 +1300 Subject: [PATCH] fix withDescription for mapped commands (#397) --- .changeset/breezy-berries-think.md | 5 +++++ src/internal/command.ts | 2 +- src/internal/commandDescriptor.ts | 2 +- test/Command.test.ts | 6 +++--- 4 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/breezy-berries-think.md diff --git a/.changeset/breezy-berries-think.md b/.changeset/breezy-berries-think.md new file mode 100644 index 0000000..3b2b02e --- /dev/null +++ b/.changeset/breezy-berries-think.md @@ -0,0 +1,5 @@ +--- +"@effect/cli": patch +--- + +fix withDescription for mapped commands diff --git a/src/internal/command.ts b/src/internal/command.ts index 12d8dc9..3ba0b4e 100644 --- a/src/internal/command.ts +++ b/src/internal/command.ts @@ -271,7 +271,7 @@ const mapDescriptor = dual< self: Command.Command, f: (_: Descriptor.Command) => Descriptor.Command ) => Command.Command ->(2, (self, f) => makeProto(f(getDescriptor(self)), self.handler, self.tag)) +>(2, (self, f) => makeProto(f(self.descriptor), self.handler, self.tag)) /** @internal */ export const prompt = ( diff --git a/src/internal/commandDescriptor.ts b/src/internal/commandDescriptor.ts index a8a0cd8..afae48f 100644 --- a/src/internal/commandDescriptor.ts +++ b/src/internal/commandDescriptor.ts @@ -858,7 +858,7 @@ const withDescriptionInternal = ( return op } case "Map": { - return map(withDescriptionInternal(self.command as Instruction, description), self.f) + return mapOrFail(withDescriptionInternal(self.command as Instruction, description), self.f) } case "OrElse": { // TODO: if both the left and right commands also have help defined, that diff --git a/test/Command.test.ts b/test/Command.test.ts index fc02f20..4e2b007 100644 --- a/test/Command.test.ts +++ b/test/Command.test.ts @@ -5,7 +5,7 @@ import { assert, describe, test } from "vitest" const git = Command.make("git", { verbose: Options.boolean("verbose").pipe(Options.withAlias("v")) -}) +}).pipe(Command.withDescription("the stupid content tracker")) const clone = Command.make("clone", { repository: Args.text({ name: "repository" }) @@ -18,7 +18,7 @@ const clone = Command.make("clone", { } else { yield* _(log(`Cloning`)) } - })) + })).pipe(Command.withDescription("Clone a repository into a new directory")) const add = Command.make("add", { pathspec: Args.text({ name: "pathspec" }) @@ -31,7 +31,7 @@ const add = Command.make("add", { } else { yield* _(log(`Adding`)) } - })) + })).pipe(Command.withDescription("Add file contents to the index")) const run = git.pipe( Command.withSubcommands([clone, add]),