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

Commit

Permalink
default CliConfig.finalCheckBuiltIn to false
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 committed Dec 7, 2023
1 parent 7456edd commit 25df0b5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-camels-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/cli": patch
---

default `CliConfig.finalCheckBuiltIn` to `false`
12 changes: 11 additions & 1 deletion src/CliConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,35 @@ import * as InternalCliConfig from "./internal/cliConfig.js"
export interface CliConfig {
/**
* Whether or not the argument parser should be case sensitive.
*
* Defaults to `false`.
*/
readonly isCaseSensitive: boolean
/**
* Threshold for when to show auto correct suggestions.
* Levenstein distance threshold for when to show auto correct suggestions.
*
* Defaults to `2`.
*/
readonly autoCorrectLimit: number
/**
* Whether or not to perform a final check of the command-line arguments for
* a built-in option, even if the provided command is not valid.
*
* Defaults to `false`.
*/
readonly finalCheckBuiltIn: boolean
/**
* Whether or not to display all the names of an option in the usage of a
* particular command.
*
* Defaults to `true`.
*/
readonly showAllNames: boolean
/**
* Whether or not to display the type of an option in the usage of a
* particular command.
*
* Defaults to `true`.
*/
readonly showTypes: boolean
}
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: true,
finalCheckBuiltIn: false,
showAllNames: true,
showTypes: true
}
Expand Down
86 changes: 46 additions & 40 deletions src/internal/commandDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,53 +499,59 @@ const parseInternal = (
case "Standard": {
const parseCommandLine = (
args: ReadonlyArray<string>
): Effect.Effect<never, ValidationError.ValidationError, ReadonlyArray<string>> => {
if (ReadonlyArray.isNonEmptyReadonlyArray(args)) {
const head = ReadonlyArray.headNonEmpty(args)
const tail = ReadonlyArray.tailNonEmpty(args)
const normalizedArgv0 = InternalCliConfig.normalizeCase(config, head)
const normalizedCommandName = InternalCliConfig.normalizeCase(config, self.name)
return Effect.succeed(tail).pipe(
Effect.when(() => normalizedArgv0 === normalizedCommandName),
Effect.flatten,
Effect.catchTag("NoSuchElementException", () => {
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
})
)
}
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
}
): Effect.Effect<never, ValidationError.ValidationError, ReadonlyArray<string>> =>
ReadonlyArray.matchLeft(args, {
onEmpty: () => {
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
},
onNonEmpty: (head, tail) => {
const normalizedArgv0 = InternalCliConfig.normalizeCase(config, head)
const normalizedCommandName = InternalCliConfig.normalizeCase(config, self.name)
return Effect.succeed(tail).pipe(
Effect.when(() => normalizedArgv0 === normalizedCommandName),
Effect.flatten,
Effect.catchTag("NoSuchElementException", () => {
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
})
)
}
})
const parseBuiltInArgs = (
args: ReadonlyArray<string>
): Effect.Effect<
FileSystem.FileSystem,
ValidationError.ValidationError,
Directive.CommandDirective<never>
> => {
if (ReadonlyArray.isNonEmptyReadonlyArray(args)) {
const argv0 = ReadonlyArray.headNonEmpty(args)
const normalizedArgv0 = InternalCliConfig.normalizeCase(config, argv0)
const normalizedCommandName = InternalCliConfig.normalizeCase(config, self.name)
if (normalizedArgv0 === normalizedCommandName) {
const help = getHelpInternal(self)
const usage = getUsageInternal(self)
const options = InternalBuiltInOptions.builtInOptions(self, usage, help)
return InternalOptions.processCommandLine(options, ReadonlyArray.drop(args, 1), config)
.pipe(
Effect.flatMap((tuple) => tuple[2]),
Effect.catchTag("NoSuchElementException", () => {
const error = InternalHelpDoc.p("No built-in option was matched")
return Effect.fail(InternalValidationError.noBuiltInMatch(error))
}),
Effect.map(InternalCommandDirective.builtIn)
)
> =>
ReadonlyArray.matchLeft(args, {
onEmpty: () => {
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
},
onNonEmpty: (argv0) => {
const normalizedArgv0 = InternalCliConfig.normalizeCase(config, argv0)
const normalizedCommandName = InternalCliConfig.normalizeCase(config, self.name)
if (normalizedArgv0 === normalizedCommandName) {
const help = getHelpInternal(self)
const usage = getUsageInternal(self)
const options = InternalBuiltInOptions.builtInOptions(self, usage, help)
const argsWithoutCommand = ReadonlyArray.drop(args, 1)
return InternalOptions.processCommandLine(options, argsWithoutCommand, config)
.pipe(
Effect.flatMap((tuple) => tuple[2]),
Effect.catchTag("NoSuchElementException", () => {
const error = InternalHelpDoc.p("No built-in option was matched")
return Effect.fail(InternalValidationError.noBuiltInMatch(error))
}),
Effect.map(InternalCommandDirective.builtIn)
)
}
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
}
}
const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
return Effect.fail(InternalValidationError.commandMismatch(error))
}
})
const parseUserDefinedArgs = (
args: ReadonlyArray<string>
): Effect.Effect<
Expand Down
1 change: 0 additions & 1 deletion test/CommandDescriptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ describe("Command", () => {
it("should create completions for the zsh shell", () =>
Effect.gen(function*(_) {
const result = yield* _(Descriptor.getZshCompletions(command, "forge"))
console.log(result)
yield* _(
Effect.promise(() => expect(result).toMatchFileSnapshot("./snapshots/zsh-completions"))
)
Expand Down

0 comments on commit 25df0b5

Please sign in to comment.