Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
fix withDescription for mapped commands (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Nov 30, 2023
1 parent 014821b commit 48db351
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-berries-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/cli": patch
---

fix withDescription for mapped commands
2 changes: 1 addition & 1 deletion src/internal/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const mapDescriptor = dual<
self: Command.Command<Name, R, E, A>,
f: (_: Descriptor.Command<A>) => Descriptor.Command<A>
) => Command.Command<Name, R, E, A>
>(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 = <Name extends string, A, R, E>(
Expand Down
2 changes: 1 addition & 1 deletion src/internal/commandDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/Command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand All @@ -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" })
Expand All @@ -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]),
Expand Down

0 comments on commit 48db351

Please sign in to comment.