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

Commit

Permalink
Merge branch 'handled' of https://github.com/Effect-TS/cli into handled
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Nov 27, 2023
2 parents 3b51110 + e6248ae commit 600e652
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 132 deletions.
28 changes: 28 additions & 0 deletions src/ValidationError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* @since 1.0.0
*/
import type { BuiltInOptions } from "./BuiltInOptions.js"
import type { Command } from "./Command.js"
import type { HelpDoc } from "./HelpDoc.js"
import * as InternalCommand from "./internal/command.js"
import * as InternalValidationError from "./internal/validationError.js"

/**
Expand All @@ -23,6 +26,7 @@ export type ValidationErrorTypeId = typeof ValidationErrorTypeId
export type ValidationError =
| CommandMismatch
| CorrectedFlag
| HelpRequested
| InvalidArgument
| InvalidValue
| MissingValue
Expand Down Expand Up @@ -50,6 +54,16 @@ export interface CorrectedFlag extends ValidationError.Proto {
readonly error: HelpDoc
}

/**
* @since 1.0.0
* @category models
*/
export interface HelpRequested extends ValidationError.Proto {
readonly _tag: "HelpRequested"
readonly error: HelpDoc
readonly showHelp: BuiltInOptions
}

/**
* @since 1.0.0
* @category models
Expand Down Expand Up @@ -159,6 +173,13 @@ export const isCommandMismatch: (self: ValidationError) => self is CommandMismat
export const isCorrectedFlag: (self: ValidationError) => self is CorrectedFlag =
InternalValidationError.isCorrectedFlag

/**
* @since 1.0.0
* @category refinements
*/
export const isHelpRequested: (self: ValidationError) => self is HelpRequested =
InternalValidationError.isHelpRequested

/**
* @since 1.0.0
* @category refinements
Expand Down Expand Up @@ -229,6 +250,13 @@ export const commandMismatch: (error: HelpDoc) => ValidationError =
export const correctedFlag: (error: HelpDoc) => ValidationError =
InternalValidationError.correctedFlag

/**
* @since 1.0.0
* @category constructors
*/
export const helpRequested: <A>(command: Command<A>) => ValidationError =
InternalCommand.helpRequestedError

/**
* @since 1.0.0
* @category constructors
Expand Down
2 changes: 1 addition & 1 deletion src/internal/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ const withDescriptionInternal = (self: Instruction, description: string): Args.A
}
}

const wizardHeader = InternalHelpDoc.p("ARGS WIZARD")
const wizardHeader = InternalHelpDoc.p("ARG WIZARD")

const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.Effect<
FileSystem.FileSystem | Terminal.Terminal,
Expand Down
4 changes: 2 additions & 2 deletions src/internal/builtInOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Option from "effect/Option"
import type * as BuiltInOptions from "../BuiltInOptions.js"
import type * as Command from "../Command.js"
import type * as HelpDoc from "../HelpDoc.js"
import * as Options from "../Options.js"
import type * as Options from "../Options.js"
import type * as Usage from "../Usage.js"
import * as InternalOptions from "./options.js"

Expand Down Expand Up @@ -62,7 +62,7 @@ export const completionsOptions: Options.Options<
["bash", "bash" as const],
["fish", "fish" as const],
["zsh", "zsh" as const]
]).pipe(Options.optional)
]).pipe(InternalOptions.optional)

/** @internal */
export const helpOptions: Options.Options<boolean> = InternalOptions.boolean("help").pipe(
Expand Down
12 changes: 10 additions & 2 deletions src/internal/cliApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ export const run = dual<
onSuccess: Effect.unifiedFn((directive) => {
switch (directive._tag) {
case "UserDefined": {
return execute(directive.value)
return execute(directive.value).pipe(
Effect.catchSome((e) =>
InternalValidationError.isValidationError(e) &&
InternalValidationError.isHelpRequested(e)
? Option.some(handleBuiltInOption(self, e.showHelp, config))
: Option.none()
)
)
}
case "BuiltIn": {
return handleBuiltInOption(self, directive.option, config).pipe(
Expand Down Expand Up @@ -210,7 +217,8 @@ const handleBuiltInOption = <A>(
])
)
const help = InternalHelpDoc.sequence(header, description)
return Console.log(InternalHelpDoc.toAnsiText(help)).pipe(
const text = InternalHelpDoc.toAnsiText(help).trimEnd()
return Console.log(text).pipe(
Effect.zipRight(InternalCommand.wizard(builtIn.command, config)),
Effect.tap((args) => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args))))
)
Expand Down
2 changes: 1 addition & 1 deletion src/internal/cliConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Tag = Context.Tag<CliConfig.CliConfig>()
export const defaultConfig: CliConfig.CliConfig = {
isCaseSensitive: false,
autoCorrectLimit: 2,
finalCheckBuiltIn: false,
finalCheckBuiltIn: true,
showAllNames: true,
showTypes: true
}
Expand Down
Loading

0 comments on commit 600e652

Please sign in to comment.