effect 4.0.0-beta.97 → 4.0.0-beta.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/Array.js +1 -1
- package/dist/Array.js.map +1 -1
- package/dist/Graph.d.ts +1187 -196
- package/dist/Graph.d.ts.map +1 -1
- package/dist/Graph.js +1031 -283
- package/dist/Graph.js.map +1 -1
- package/dist/Iterable.d.ts.map +1 -1
- package/dist/Iterable.js +41 -1
- package/dist/Iterable.js.map +1 -1
- package/dist/LayerRef.d.ts +4 -6
- package/dist/LayerRef.d.ts.map +1 -1
- package/dist/LayerRef.js +4 -6
- package/dist/LayerRef.js.map +1 -1
- package/dist/Number.d.ts.map +1 -1
- package/dist/Number.js +28 -10
- package/dist/Number.js.map +1 -1
- package/dist/Schema.d.ts +22 -22
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +37 -34
- package/dist/Schema.js.map +1 -1
- package/dist/SchemaAST.d.ts.map +1 -1
- package/dist/SchemaAST.js +25 -10
- package/dist/SchemaAST.js.map +1 -1
- package/dist/SchemaError.d.ts +53 -0
- package/dist/SchemaError.d.ts.map +1 -0
- package/dist/SchemaError.js +61 -0
- package/dist/SchemaError.js.map +1 -0
- package/dist/SchemaGetter.d.ts.map +1 -1
- package/dist/SchemaGetter.js +17 -12
- package/dist/SchemaGetter.js.map +1 -1
- package/dist/SchemaRepresentation.d.ts.map +1 -1
- package/dist/SchemaRepresentation.js +186 -224
- package/dist/SchemaRepresentation.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/effect.js +35 -11
- package/dist/internal/effect.js.map +1 -1
- package/dist/internal/schema/equivalence.js +1 -2
- package/dist/internal/schema/equivalence.js.map +1 -1
- package/dist/internal/schema/representation.js +1 -3
- package/dist/internal/schema/representation.js.map +1 -1
- package/dist/internal/schema/schema.d.ts +0 -13
- package/dist/internal/schema/schema.d.ts.map +1 -1
- package/dist/internal/schema/schema.js +4 -29
- package/dist/internal/schema/schema.js.map +1 -1
- package/dist/unstable/ai/Tool.d.ts.map +1 -1
- package/dist/unstable/ai/Tool.js +11 -13
- package/dist/unstable/ai/Tool.js.map +1 -1
- package/dist/unstable/cli/CliConfig.d.ts +76 -0
- package/dist/unstable/cli/CliConfig.d.ts.map +1 -0
- package/dist/unstable/cli/CliConfig.js +63 -0
- package/dist/unstable/cli/CliConfig.js.map +1 -0
- package/dist/unstable/cli/CliError.d.ts +8 -16
- package/dist/unstable/cli/CliError.d.ts.map +1 -1
- package/dist/unstable/cli/CliError.js +11 -16
- package/dist/unstable/cli/CliError.js.map +1 -1
- package/dist/unstable/cli/Command.d.ts +40 -4
- package/dist/unstable/cli/Command.d.ts.map +1 -1
- package/dist/unstable/cli/Command.js +63 -6
- package/dist/unstable/cli/Command.js.map +1 -1
- package/dist/unstable/cli/GlobalFlag.d.ts +24 -5
- package/dist/unstable/cli/GlobalFlag.d.ts.map +1 -1
- package/dist/unstable/cli/GlobalFlag.js +26 -10
- package/dist/unstable/cli/GlobalFlag.js.map +1 -1
- package/dist/unstable/cli/Param.js +6 -2
- package/dist/unstable/cli/Param.js.map +1 -1
- package/dist/unstable/cli/index.d.ts +4 -0
- package/dist/unstable/cli/index.d.ts.map +1 -1
- package/dist/unstable/cli/index.js +4 -0
- package/dist/unstable/cli/index.js.map +1 -1
- package/dist/unstable/cli/internal/ansi.d.ts.map +1 -1
- package/dist/unstable/cli/internal/ansi.js +2 -0
- package/dist/unstable/cli/internal/ansi.js.map +1 -1
- package/dist/unstable/cli/internal/parser.js +11 -2
- package/dist/unstable/cli/internal/parser.js.map +1 -1
- package/dist/unstable/cli/internal/wizard.d.ts +13 -0
- package/dist/unstable/cli/internal/wizard.d.ts.map +1 -0
- package/dist/unstable/cli/internal/wizard.js +212 -0
- package/dist/unstable/cli/internal/wizard.js.map +1 -0
- package/dist/unstable/cluster/EntityProxyServer.d.ts +1 -1
- package/dist/unstable/cluster/EntityProxyServer.d.ts.map +1 -1
- package/dist/unstable/cluster/EntityProxyServer.js +2 -4
- package/dist/unstable/cluster/EntityProxyServer.js.map +1 -1
- package/dist/unstable/cluster/RunnerStorage.js +1 -1
- package/dist/unstable/cluster/RunnerStorage.js.map +1 -1
- package/dist/unstable/cluster/internal/entityManager.js +15 -12
- package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
- package/dist/unstable/http/Multipart.d.ts.map +1 -1
- package/dist/unstable/http/Multipart.js +3 -1
- package/dist/unstable/http/Multipart.js.map +1 -1
- package/dist/unstable/httpapi/HttpApi.d.ts +36 -15
- package/dist/unstable/httpapi/HttpApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApi.js +19 -20
- package/dist/unstable/httpapi/HttpApi.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts +51 -62
- package/dist/unstable/httpapi/HttpApiBuilder.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiBuilder.js +68 -58
- package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.d.ts +53 -53
- package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiClient.js +40 -30
- package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +165 -164
- package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiEndpoint.js +31 -19
- package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.d.ts +22 -0
- package/dist/unstable/httpapi/HttpApiError.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiError.js +31 -0
- package/dist/unstable/httpapi/HttpApiError.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.d.ts +55 -30
- package/dist/unstable/httpapi/HttpApiGroup.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiGroup.js +22 -29
- package/dist/unstable/httpapi/HttpApiGroup.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts +8 -8
- package/dist/unstable/httpapi/HttpApiMiddleware.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiMiddleware.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.d.ts +2 -2
- package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiScalar.js +4 -3
- package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.d.ts +8 -0
- package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiSwagger.js.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.d.ts +4 -4
- package/dist/unstable/httpapi/HttpApiTest.d.ts.map +1 -1
- package/dist/unstable/httpapi/HttpApiTest.js +9 -8
- package/dist/unstable/httpapi/HttpApiTest.js.map +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts +1 -1
- package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
- package/dist/unstable/httpapi/OpenApi.js +77 -37
- package/dist/unstable/httpapi/OpenApi.js.map +1 -1
- package/dist/unstable/httpapi/internal/html.js +6 -2
- package/dist/unstable/httpapi/internal/html.js.map +1 -1
- package/dist/unstable/httpapi/internal/mediaType.d.ts +2 -0
- package/dist/unstable/httpapi/internal/mediaType.d.ts.map +1 -0
- package/dist/unstable/httpapi/internal/mediaType.js +7 -0
- package/dist/unstable/httpapi/internal/mediaType.js.map +1 -0
- package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
- package/dist/unstable/persistence/PersistedQueue.js +16 -12
- package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
- package/dist/unstable/persistence/Redis.d.ts.map +1 -1
- package/dist/unstable/persistence/Redis.js +5 -3
- package/dist/unstable/persistence/Redis.js.map +1 -1
- package/dist/unstable/reactivity/Atom.js +1 -1
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +7 -7
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +3 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts +3 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +6 -3
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/sql/SqlClient.d.ts +1 -2
- package/dist/unstable/sql/SqlClient.d.ts.map +1 -1
- package/dist/unstable/sql/SqlClient.js.map +1 -1
- package/dist/unstable/workflow/DurableDeferred.js +1 -1
- package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.d.ts.map +1 -1
- package/dist/unstable/workflow/WorkflowProxyServer.js +1 -2
- package/dist/unstable/workflow/WorkflowProxyServer.js.map +1 -1
- package/package.json +3 -3
- package/src/Array.ts +1 -1
- package/src/Graph.ts +2967 -457
- package/src/Iterable.ts +32 -2
- package/src/LayerRef.ts +4 -6
- package/src/Number.ts +29 -10
- package/src/Schema.ts +43 -35
- package/src/SchemaAST.ts +25 -13
- package/src/SchemaError.ts +64 -0
- package/src/SchemaGetter.ts +22 -16
- package/src/SchemaRepresentation.ts +165 -202
- package/src/index.ts +10 -0
- package/src/internal/effect.ts +48 -25
- package/src/internal/schema/equivalence.ts +1 -2
- package/src/internal/schema/representation.ts +4 -4
- package/src/internal/schema/schema.ts +4 -37
- package/src/unstable/ai/Tool.ts +13 -16
- package/src/unstable/cli/CliConfig.ts +85 -0
- package/src/unstable/cli/CliError.ts +27 -16
- package/src/unstable/cli/Command.ts +90 -14
- package/src/unstable/cli/GlobalFlag.ts +46 -29
- package/src/unstable/cli/Param.ts +15 -3
- package/src/unstable/cli/index.ts +5 -0
- package/src/unstable/cli/internal/ansi.ts +3 -0
- package/src/unstable/cli/internal/parser.ts +14 -2
- package/src/unstable/cli/internal/wizard.ts +283 -0
- package/src/unstable/cluster/EntityProxyServer.ts +15 -17
- package/src/unstable/cluster/RunnerStorage.ts +1 -1
- package/src/unstable/cluster/internal/entityManager.ts +48 -34
- package/src/unstable/http/Multipart.ts +3 -1
- package/src/unstable/httpapi/HttpApi.ts +72 -47
- package/src/unstable/httpapi/HttpApiBuilder.ts +320 -217
- package/src/unstable/httpapi/HttpApiClient.ts +196 -151
- package/src/unstable/httpapi/HttpApiEndpoint.ts +251 -447
- package/src/unstable/httpapi/HttpApiError.ts +33 -0
- package/src/unstable/httpapi/HttpApiGroup.ts +95 -74
- package/src/unstable/httpapi/HttpApiMiddleware.ts +10 -7
- package/src/unstable/httpapi/HttpApiScalar.ts +15 -12
- package/src/unstable/httpapi/HttpApiSchema.ts +8 -0
- package/src/unstable/httpapi/HttpApiSwagger.ts +2 -2
- package/src/unstable/httpapi/HttpApiTest.ts +15 -14
- package/src/unstable/httpapi/OpenApi.ts +74 -36
- package/src/unstable/httpapi/internal/html.ts +9 -2
- package/src/unstable/httpapi/internal/mediaType.ts +6 -0
- package/src/unstable/persistence/PersistedQueue.ts +16 -14
- package/src/unstable/persistence/Redis.ts +9 -4
- package/src/unstable/reactivity/Atom.ts +1 -1
- package/src/unstable/reactivity/AtomHttpApi.ts +164 -162
- package/src/unstable/rpc/RpcServer.ts +10 -4
- package/src/unstable/sql/SqlClient.ts +1 -2
- package/src/unstable/workflow/DurableDeferred.ts +1 -1
- package/src/unstable/workflow/WorkflowProxyServer.ts +11 -12
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as Cause from "../../Cause.ts"
|
|
2
|
-
import * as Data from "../../Data.ts"
|
|
3
2
|
import * as Effect from "../../Effect.ts"
|
|
4
|
-
import * as Exit from "../../Exit.ts"
|
|
5
3
|
import * as Pipeable from "../../Pipeable.ts"
|
|
6
4
|
import type * as Schema from "../../Schema.ts"
|
|
7
5
|
import * as SchemaAST from "../../SchemaAST.ts"
|
|
6
|
+
import { SchemaError } from "../../SchemaError.ts"
|
|
8
7
|
import type { Issue } from "../../SchemaIssue.ts"
|
|
9
8
|
import * as SchemaParser from "../../SchemaParser.ts"
|
|
10
9
|
|
|
@@ -35,34 +34,16 @@ export function make<S extends Schema.Constraint>(ast: S["ast"], options?: objec
|
|
|
35
34
|
}
|
|
36
35
|
self.ast = ast
|
|
37
36
|
self.rebuild = (ast: SchemaAST.AST) => make(ast, options)
|
|
37
|
+
const makeEffect = SchemaParser.makeEffect(self)
|
|
38
38
|
self.makeEffect = (input: S["~type.make.in"], options?: Schema.MakeOptions) =>
|
|
39
|
-
|
|
39
|
+
fromIssueEffect(makeEffect(input, options))
|
|
40
40
|
self.make = SchemaParser.make(self)
|
|
41
41
|
self.makeOption = SchemaParser.makeOption(self)
|
|
42
42
|
return self
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/** @internal */
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
// purposefully not internal
|
|
49
|
-
export class SchemaError extends Data.TaggedError("SchemaError")<{
|
|
50
|
-
readonly issue: Issue
|
|
51
|
-
}> {
|
|
52
|
-
readonly [SchemaErrorTypeId]: typeof SchemaErrorTypeId = SchemaErrorTypeId
|
|
53
|
-
constructor(issue: Issue) {
|
|
54
|
-
super({ issue })
|
|
55
|
-
}
|
|
56
|
-
override get message() {
|
|
57
|
-
return this.issue.toString()
|
|
58
|
-
}
|
|
59
|
-
override toString() {
|
|
60
|
-
return `SchemaError(${this.message})`
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** @internal */
|
|
65
|
-
export function mapSchemaIssueEffect<A, R>(
|
|
46
|
+
export function fromIssueEffect<A, R>(
|
|
66
47
|
self: Effect.Effect<A, Issue, R>
|
|
67
48
|
): Effect.Effect<A, SchemaError, R> {
|
|
68
49
|
return Effect.catchCause(
|
|
@@ -71,20 +52,6 @@ export function mapSchemaIssueEffect<A, R>(
|
|
|
71
52
|
)
|
|
72
53
|
}
|
|
73
54
|
|
|
74
|
-
/** @internal */
|
|
75
|
-
export function mapSchemaErrorEffect<A, R>(
|
|
76
|
-
self: Effect.Effect<A, SchemaError, R>
|
|
77
|
-
): Effect.Effect<A, Issue, R> {
|
|
78
|
-
return Effect.catchCause(self, (cause) => Effect.failCauseSync(() => Cause.map(cause, (error) => error.issue)))
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** @internal */
|
|
82
|
-
export function mapSchemaIssueExit<A>(exit: Exit.Exit<A, Issue>): Exit.Exit<A, SchemaError> {
|
|
83
|
-
return Exit.isSuccess(exit)
|
|
84
|
-
? Exit.succeed(exit.value)
|
|
85
|
-
: Exit.failCause(Cause.map(exit.cause, (issue) => new SchemaError(issue)))
|
|
86
|
-
}
|
|
87
|
-
|
|
88
55
|
/** @internal */
|
|
89
56
|
export const jsonReorder = makeReorder(getJsonPriority)
|
|
90
57
|
|
package/src/unstable/ai/Tool.ts
CHANGED
|
@@ -1028,37 +1028,34 @@ export type RequiresHandler<Tool extends Any> = Tool extends ProviderDefined<
|
|
|
1028
1028
|
// Constructors
|
|
1029
1029
|
// =============================================================================
|
|
1030
1030
|
|
|
1031
|
+
// Clones a tool while preserving its prototype (and thus its kind, e.g.
|
|
1032
|
+
// user-defined vs. provider-defined vs. dynamic) and its own properties such
|
|
1033
|
+
// as `id`. Optional `overrides` replace individual fields on the clone.
|
|
1034
|
+
const clone = (self: Any, overrides?: Record<string, unknown>): any =>
|
|
1035
|
+
Object.assign(Object.create(Object.getPrototypeOf(self)), self, overrides)
|
|
1036
|
+
|
|
1031
1037
|
const Proto = {
|
|
1032
1038
|
[TypeId]: { _Requirements: identity },
|
|
1033
1039
|
pipe() {
|
|
1034
1040
|
return pipeArguments(this, arguments)
|
|
1035
1041
|
},
|
|
1036
1042
|
addDependency(this: Any) {
|
|
1037
|
-
return
|
|
1043
|
+
return clone(this)
|
|
1038
1044
|
},
|
|
1039
1045
|
setParameters(this: Any, parametersSchema: Schema.Constraint) {
|
|
1040
|
-
return
|
|
1041
|
-
...this,
|
|
1042
|
-
parametersSchema
|
|
1043
|
-
})
|
|
1046
|
+
return clone(this, { parametersSchema })
|
|
1044
1047
|
},
|
|
1045
1048
|
setSuccess(this: Any, successSchema: Schema.Constraint) {
|
|
1046
|
-
return
|
|
1049
|
+
return clone(this, { successSchema })
|
|
1047
1050
|
},
|
|
1048
1051
|
setFailure(this: Any, failureSchema: Schema.Constraint) {
|
|
1049
|
-
return
|
|
1052
|
+
return clone(this, { failureSchema })
|
|
1050
1053
|
},
|
|
1051
1054
|
annotate<I, S>(this: Any, tag: Context.Key<I, S>, value: S) {
|
|
1052
|
-
return
|
|
1053
|
-
...this,
|
|
1054
|
-
annotations: Context.add(this.annotations, tag, value)
|
|
1055
|
-
})
|
|
1055
|
+
return clone(this, { annotations: Context.add(this.annotations, tag, value) })
|
|
1056
1056
|
},
|
|
1057
1057
|
annotateMerge<I>(this: Any, context: Context.Context<I>) {
|
|
1058
|
-
return
|
|
1059
|
-
...this,
|
|
1060
|
-
annotations: Context.merge(this.annotations, context)
|
|
1061
|
-
})
|
|
1058
|
+
return clone(this, { annotations: Context.merge(this.annotations, context) })
|
|
1062
1059
|
}
|
|
1063
1060
|
}
|
|
1064
1061
|
|
|
@@ -1132,7 +1129,7 @@ const providerDefinedProto = <
|
|
|
1132
1129
|
readonly failureMode: Mode
|
|
1133
1130
|
},
|
|
1134
1131
|
RequiresHandler
|
|
1135
|
-
> => Object.assign(Object.create(ProviderDefinedProto), { ...options })
|
|
1132
|
+
> => Object.assign(Object.create(ProviderDefinedProto), { annotations: Context.empty(), ...options })
|
|
1136
1133
|
|
|
1137
1134
|
const dynamicProto = <
|
|
1138
1135
|
const Name extends string,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for Effect CLI command execution.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "../../Context.ts"
|
|
7
|
+
import * as Layer from "../../Layer.ts"
|
|
8
|
+
import * as GlobalFlag from "./GlobalFlag.ts"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Context reference for configuration shared by CLI parsing, help generation,
|
|
12
|
+
* and command execution.
|
|
13
|
+
*
|
|
14
|
+
* **When to use**
|
|
15
|
+
*
|
|
16
|
+
* Use when you need to customize runner-wide CLI behavior, such as which
|
|
17
|
+
* built-in global flags are available.
|
|
18
|
+
*
|
|
19
|
+
* @category services
|
|
20
|
+
* @since 4.0.0
|
|
21
|
+
*/
|
|
22
|
+
export class CliConfig extends Context.Reference<CliConfig.Service>("effect/unstable/cli/CliConfig", {
|
|
23
|
+
defaultValue: () => defaults
|
|
24
|
+
}) {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Types used by the `CliConfig` context reference.
|
|
28
|
+
*
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
export declare namespace CliConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Configuration values used while running a CLI command.
|
|
34
|
+
*
|
|
35
|
+
* @category models
|
|
36
|
+
* @since 4.0.0
|
|
37
|
+
*/
|
|
38
|
+
export interface Service {
|
|
39
|
+
/** Ordered built-in global flags, with earlier action flags taking precedence. */
|
|
40
|
+
readonly builtIns: ReadonlyArray<GlobalFlag.BuiltIn>
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Default CLI configuration containing every built-in global flag.
|
|
46
|
+
*
|
|
47
|
+
* @category defaults
|
|
48
|
+
* @since 4.0.0
|
|
49
|
+
*/
|
|
50
|
+
export const defaults: CliConfig.Service = {
|
|
51
|
+
builtIns: GlobalFlag.BuiltIns
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Creates CLI configuration by merging the provided options over `defaults`.
|
|
56
|
+
*
|
|
57
|
+
* **When to use**
|
|
58
|
+
*
|
|
59
|
+
* Use when you need a configuration value to provide directly through the
|
|
60
|
+
* `CliConfig` context reference.
|
|
61
|
+
*
|
|
62
|
+
* @see {@link layer} for providing configuration as a layer
|
|
63
|
+
*
|
|
64
|
+
* @category constructors
|
|
65
|
+
* @since 4.0.0
|
|
66
|
+
*/
|
|
67
|
+
export const make = (options?: Partial<CliConfig.Service>): CliConfig.Service => ({
|
|
68
|
+
...defaults,
|
|
69
|
+
...options
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Creates a layer that provides CLI configuration merged over `defaults`.
|
|
74
|
+
*
|
|
75
|
+
* **When to use**
|
|
76
|
+
*
|
|
77
|
+
* Use when wiring customized CLI behavior into an application layer.
|
|
78
|
+
*
|
|
79
|
+
* @see {@link make} for creating a configuration value directly
|
|
80
|
+
*
|
|
81
|
+
* @category layers
|
|
82
|
+
* @since 4.0.0
|
|
83
|
+
*/
|
|
84
|
+
export const layer = (options?: Partial<CliConfig.Service>): Layer.Layer<never> =>
|
|
85
|
+
Layer.succeed(CliConfig, make(options))
|
|
@@ -127,8 +127,9 @@ export type CliError =
|
|
|
127
127
|
* @category models
|
|
128
128
|
* @since 4.0.0
|
|
129
129
|
*/
|
|
130
|
-
export class UnrecognizedOption extends Schema.
|
|
131
|
-
|
|
130
|
+
export class UnrecognizedOption extends Schema.TaggedErrorClass<UnrecognizedOption>(
|
|
131
|
+
`${TypeId}/UnrecognizedOption`
|
|
132
|
+
)("UnrecognizedOption", {
|
|
132
133
|
option: Schema.String,
|
|
133
134
|
command: Schema.optional(Schema.Array(Schema.String)),
|
|
134
135
|
suggestions: Schema.Array(Schema.String)
|
|
@@ -178,8 +179,9 @@ export class UnrecognizedOption extends Schema.ErrorClass<UnrecognizedOption>(`$
|
|
|
178
179
|
* @category models
|
|
179
180
|
* @since 4.0.0
|
|
180
181
|
*/
|
|
181
|
-
export class DuplicateOption extends Schema.
|
|
182
|
-
|
|
182
|
+
export class DuplicateOption extends Schema.TaggedErrorClass<DuplicateOption>(
|
|
183
|
+
`${TypeId}/DuplicateOption`
|
|
184
|
+
)("DuplicateOption", {
|
|
183
185
|
option: Schema.String,
|
|
184
186
|
parentCommand: Schema.String,
|
|
185
187
|
childCommand: Schema.String
|
|
@@ -232,8 +234,9 @@ export class DuplicateOption extends Schema.ErrorClass<DuplicateOption>(`${TypeI
|
|
|
232
234
|
* @category models
|
|
233
235
|
* @since 4.0.0
|
|
234
236
|
*/
|
|
235
|
-
export class MissingOption extends Schema.
|
|
236
|
-
|
|
237
|
+
export class MissingOption extends Schema.TaggedErrorClass<MissingOption>(
|
|
238
|
+
`${TypeId}/MissingOption`
|
|
239
|
+
)("MissingOption", {
|
|
237
240
|
option: Schema.String
|
|
238
241
|
}) {
|
|
239
242
|
/**
|
|
@@ -282,8 +285,9 @@ export class MissingOption extends Schema.ErrorClass<MissingOption>(`${TypeId}/M
|
|
|
282
285
|
* @category models
|
|
283
286
|
* @since 4.0.0
|
|
284
287
|
*/
|
|
285
|
-
export class MissingArgument extends Schema.
|
|
286
|
-
|
|
288
|
+
export class MissingArgument extends Schema.TaggedErrorClass<MissingArgument>(
|
|
289
|
+
`${TypeId}/MissingArgument`
|
|
290
|
+
)("MissingArgument", {
|
|
287
291
|
argument: Schema.String
|
|
288
292
|
}) {
|
|
289
293
|
/**
|
|
@@ -337,8 +341,9 @@ export class MissingArgument extends Schema.ErrorClass<MissingArgument>(`${TypeI
|
|
|
337
341
|
* @category models
|
|
338
342
|
* @since 4.0.0
|
|
339
343
|
*/
|
|
340
|
-
export class InvalidValue extends Schema.
|
|
341
|
-
|
|
344
|
+
export class InvalidValue extends Schema.TaggedErrorClass<InvalidValue>(
|
|
345
|
+
`${TypeId}/InvalidValue`
|
|
346
|
+
)("InvalidValue", {
|
|
342
347
|
option: Schema.String,
|
|
343
348
|
value: Schema.String,
|
|
344
349
|
expected: Schema.String,
|
|
@@ -360,6 +365,9 @@ export class InvalidValue extends Schema.ErrorClass<InvalidValue>(`${TypeId}/Inv
|
|
|
360
365
|
if (this.kind === "argument") {
|
|
361
366
|
return `Invalid value for argument <${this.option}>: "${this.value}". Expected: ${this.expected}`
|
|
362
367
|
}
|
|
368
|
+
if (this.value.length === 0) {
|
|
369
|
+
return `Missing value for flag --${this.option}. Expected: ${this.expected}`
|
|
370
|
+
}
|
|
363
371
|
return `Invalid value for flag --${this.option}: "${this.value}". Expected: ${this.expected}`
|
|
364
372
|
}
|
|
365
373
|
}
|
|
@@ -400,8 +408,9 @@ export class InvalidValue extends Schema.ErrorClass<InvalidValue>(`${TypeId}/Inv
|
|
|
400
408
|
* @category models
|
|
401
409
|
* @since 4.0.0
|
|
402
410
|
*/
|
|
403
|
-
export class UnknownSubcommand extends Schema.
|
|
404
|
-
|
|
411
|
+
export class UnknownSubcommand extends Schema.TaggedErrorClass<UnknownSubcommand>(
|
|
412
|
+
`${TypeId}/UnknownSubcommand`
|
|
413
|
+
)("UnknownSubcomand", {
|
|
405
414
|
subcommand: Schema.String,
|
|
406
415
|
parent: Schema.optional(Schema.Array(Schema.String)),
|
|
407
416
|
suggestions: Schema.Array(Schema.String)
|
|
@@ -464,8 +473,9 @@ export class UnknownSubcommand extends Schema.ErrorClass<UnknownSubcommand>(`${T
|
|
|
464
473
|
* @category models
|
|
465
474
|
* @since 4.0.0
|
|
466
475
|
*/
|
|
467
|
-
export class UserError extends Schema.
|
|
468
|
-
|
|
476
|
+
export class UserError extends Schema.TaggedErrorClass<UserError>(
|
|
477
|
+
`${TypeId}/UserError`
|
|
478
|
+
)("UserError", {
|
|
469
479
|
cause: Schema.Defect()
|
|
470
480
|
}) {
|
|
471
481
|
/**
|
|
@@ -533,8 +543,9 @@ export type NonShowHelpErrors = typeof NonShowHelpErrors.Type
|
|
|
533
543
|
* @category models
|
|
534
544
|
* @since 4.0.0
|
|
535
545
|
*/
|
|
536
|
-
export class ShowHelp extends Schema.
|
|
537
|
-
|
|
546
|
+
export class ShowHelp extends Schema.TaggedErrorClass<ShowHelp>(
|
|
547
|
+
`${TypeId}/ShowHelp`
|
|
548
|
+
)("ShowHelp", {
|
|
538
549
|
commandPath: Schema.Array(Schema.String),
|
|
539
550
|
errors: Schema.Array(NonShowHelpErrors)
|
|
540
551
|
}) {
|
|
@@ -26,6 +26,7 @@ import * as Stdio from "../../Stdio.ts"
|
|
|
26
26
|
import * as Terminal from "../../Terminal.ts"
|
|
27
27
|
import type { Contravariant, Covariant, NoInfer, Simplify } from "../../Types.ts"
|
|
28
28
|
import type { ChildProcessSpawner } from "../process/ChildProcessSpawner.ts"
|
|
29
|
+
import * as CliConfig from "./CliConfig.ts"
|
|
29
30
|
import * as CliError from "./CliError.ts"
|
|
30
31
|
import * as CliOutput from "./CliOutput.ts"
|
|
31
32
|
import * as GlobalFlag from "./GlobalFlag.ts"
|
|
@@ -34,7 +35,9 @@ import { mergeConfig, parseConfig } from "./internal/config.ts"
|
|
|
34
35
|
import { getGlobalFlagsForCommandPath, getGlobalFlagsForCommandTree, getHelpForCommandPath } from "./internal/help.ts"
|
|
35
36
|
import * as Lexer from "./internal/lexer.ts"
|
|
36
37
|
import * as Parser from "./internal/parser.ts"
|
|
38
|
+
import * as Wizard from "./internal/wizard.ts"
|
|
37
39
|
import * as Param from "./Param.ts"
|
|
40
|
+
import * as Prompt from "./Prompt.ts"
|
|
38
41
|
|
|
39
42
|
/* ========================================================================== */
|
|
40
43
|
/* Public Types */
|
|
@@ -369,6 +372,21 @@ export type Error<C> = C extends Command<
|
|
|
369
372
|
> ? _Error :
|
|
370
373
|
never
|
|
371
374
|
|
|
375
|
+
/**
|
|
376
|
+
* A utility type to extract the required services type from a `Command`.
|
|
377
|
+
*
|
|
378
|
+
* @category utility types
|
|
379
|
+
* @since 4.0.0
|
|
380
|
+
*/
|
|
381
|
+
export type Services<C> = C extends Command<
|
|
382
|
+
infer _Name,
|
|
383
|
+
infer _Input,
|
|
384
|
+
infer _ContextInput,
|
|
385
|
+
infer _Error,
|
|
386
|
+
infer _Requirements
|
|
387
|
+
> ? _Requirements :
|
|
388
|
+
never
|
|
389
|
+
|
|
372
390
|
/**
|
|
373
391
|
* Service context for a specific command, enabling subcommands to access their parent's parsed configuration.
|
|
374
392
|
*
|
|
@@ -697,7 +715,7 @@ export const make: {
|
|
|
697
715
|
name: Name,
|
|
698
716
|
config: Config,
|
|
699
717
|
handler: (config: Command.Config.Infer<Config>) => Effect.Effect<void, E, R>
|
|
700
|
-
): Command<Name, Command.Config.Infer<Config>, {}, E, Exclude<R,
|
|
718
|
+
): Command<Name, Command.Config.Infer<Config>, {}, E, Exclude<R, BuiltInSettingContext>>
|
|
701
719
|
} = ((
|
|
702
720
|
name: string,
|
|
703
721
|
config?: Command.Config,
|
|
@@ -772,7 +790,7 @@ export const withHandler: {
|
|
|
772
790
|
*/
|
|
773
791
|
<A, R, E>(handler: (value: A) => Effect.Effect<void, E, R>): <Name extends string, XR, XE, ContextInput>(
|
|
774
792
|
self: Command<Name, A, ContextInput, XE, XR>
|
|
775
|
-
) => Command<Name, A, ContextInput, E, Exclude<R,
|
|
793
|
+
) => Command<Name, A, ContextInput, E, Exclude<R, BuiltInSettingContext>>
|
|
776
794
|
/* ========================================================================== */
|
|
777
795
|
/* Combinators */
|
|
778
796
|
/* ========================================================================== */
|
|
@@ -805,11 +823,11 @@ export const withHandler: {
|
|
|
805
823
|
<Name extends string, A, XR, XE, R, E, ContextInput>(
|
|
806
824
|
self: Command<Name, A, ContextInput, XE, XR>,
|
|
807
825
|
handler: (value: A) => Effect.Effect<void, E, R>
|
|
808
|
-
): Command<Name, A, ContextInput, E, Exclude<R,
|
|
826
|
+
): Command<Name, A, ContextInput, E, Exclude<R, BuiltInSettingContext>>
|
|
809
827
|
} = dual(2, <Name extends string, A, XR, XE, R, E, ContextInput>(
|
|
810
828
|
self: Command<Name, A, ContextInput, XE, XR>,
|
|
811
829
|
handler: (value: A) => Effect.Effect<void, E, R>
|
|
812
|
-
): Command<Name, A, ContextInput, E, Exclude<R,
|
|
830
|
+
): Command<Name, A, ContextInput, E, Exclude<R, BuiltInSettingContext>> =>
|
|
813
831
|
makeCommand({ ...toImpl(self), handle: handler } as any))
|
|
814
832
|
|
|
815
833
|
interface SubcommandGroupInternal {
|
|
@@ -1272,12 +1290,12 @@ type ExtractGlobalFlagContext<T extends ReadonlyArray<GlobalFlag.GlobalFlag<any>
|
|
|
1272
1290
|
? F extends GlobalFlag.Setting<infer Id, infer _A> ? GlobalFlag.Setting.Identifier<Id>
|
|
1273
1291
|
: never
|
|
1274
1292
|
: never
|
|
1293
|
+
type BuiltInSettingContext = ExtractGlobalFlagContext<typeof GlobalFlag.BuiltIns>
|
|
1275
1294
|
type ExtractSubcommand<T> = T extends Command<infer _Name, infer _Input, infer _CI, infer _E, infer _R> ? T
|
|
1276
1295
|
: T extends Command.SubcommandGroup<infer Commands> ? Commands[number]
|
|
1277
1296
|
: never
|
|
1278
1297
|
type ExtractSubcommandErrors<T extends ReadonlyArray<Command.SubcommandEntry>> = Error<ExtractSubcommand<T[number]>>
|
|
1279
|
-
type ExtractSubcommandContext<T extends ReadonlyArray<Command.SubcommandEntry>> = ExtractSubcommand<T[number]
|
|
1280
|
-
Command<infer _Name, infer _Input, infer _CI, infer _E, infer _R> ? _R : never
|
|
1298
|
+
type ExtractSubcommandContext<T extends ReadonlyArray<Command.SubcommandEntry>> = Services<ExtractSubcommand<T[number]>>
|
|
1281
1299
|
|
|
1282
1300
|
/**
|
|
1283
1301
|
* Sets the description for a command.
|
|
@@ -2065,6 +2083,38 @@ export const provideEffectDiscard: {
|
|
|
2065
2083
|
/* Execution */
|
|
2066
2084
|
/* ========================================================================== */
|
|
2067
2085
|
|
|
2086
|
+
/**
|
|
2087
|
+
* Interactively constructs command-line arguments for a command.
|
|
2088
|
+
*
|
|
2089
|
+
* **Details**
|
|
2090
|
+
*
|
|
2091
|
+
* The returned arguments include the command name and can be inspected,
|
|
2092
|
+
* modified, or passed to another command runner by the caller.
|
|
2093
|
+
*
|
|
2094
|
+
* **Example** (Constructing command arguments)
|
|
2095
|
+
*
|
|
2096
|
+
* ```ts
|
|
2097
|
+
* import { Console, Effect } from "effect"
|
|
2098
|
+
* import { Command } from "effect/unstable/cli"
|
|
2099
|
+
*
|
|
2100
|
+
* const command = Command.make("app")
|
|
2101
|
+
*
|
|
2102
|
+
* const program = Effect.gen(function*() {
|
|
2103
|
+
* const args = yield* Command.wizard(command)
|
|
2104
|
+
* yield* Console.log(args.join(" "))
|
|
2105
|
+
* })
|
|
2106
|
+
* ```
|
|
2107
|
+
*
|
|
2108
|
+
* @category command execution
|
|
2109
|
+
* @since 4.0.0
|
|
2110
|
+
*/
|
|
2111
|
+
export const wizard = <Name extends string, Input, E, R, ContextInput>(
|
|
2112
|
+
command: Command<Name, Input, ContextInput, E, R>,
|
|
2113
|
+
options?: {
|
|
2114
|
+
readonly prefix?: ReadonlyArray<string> | undefined
|
|
2115
|
+
} | undefined
|
|
2116
|
+
): Effect.Effect<Array<string>, CliError.CliError | Terminal.QuitError, Environment> => Wizard.run(command, options)
|
|
2117
|
+
|
|
2068
2118
|
const getOutOfScopeGlobalFlagErrors = (
|
|
2069
2119
|
allFlags: ReadonlyArray<GlobalFlag.GlobalFlag<any>>,
|
|
2070
2120
|
activeFlags: ReadonlyArray<GlobalFlag.GlobalFlag<any>>,
|
|
@@ -2109,8 +2159,9 @@ const showHelp = <Name extends string, Input, E, R, ContextInput>(
|
|
|
2109
2159
|
error: CliError.ShowHelp
|
|
2110
2160
|
): Effect.Effect<void, CliError.CliError, Environment> =>
|
|
2111
2161
|
Effect.gen(function*() {
|
|
2162
|
+
const { builtIns } = yield* CliConfig.CliConfig
|
|
2112
2163
|
const formatter = yield* CliOutput.Formatter
|
|
2113
|
-
const helpDoc = yield* getHelpForCommandPath(command, error.commandPath,
|
|
2164
|
+
const helpDoc = yield* getHelpForCommandPath(command, error.commandPath, builtIns)
|
|
2114
2165
|
yield* Console.log(formatter.formatHelpDoc(helpDoc))
|
|
2115
2166
|
if (error.errors.length > 0) {
|
|
2116
2167
|
yield* Console.error(formatter.formatErrors(error.errors as any))
|
|
@@ -2293,10 +2344,11 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
|
|
|
2293
2344
|
const commandImpl = toImpl(command)
|
|
2294
2345
|
return Effect.fnUntraced(
|
|
2295
2346
|
function*(args: ReadonlyArray<string>) {
|
|
2347
|
+
const { builtIns } = yield* CliConfig.CliConfig
|
|
2296
2348
|
const { tokens, trailingOperands } = Lexer.lex(args)
|
|
2297
2349
|
|
|
2298
2350
|
// 1. Collect known global flags from the command tree
|
|
2299
|
-
const allFlags = getGlobalFlagsForCommandTree(command,
|
|
2351
|
+
const allFlags = getGlobalFlagsForCommandTree(command, builtIns)
|
|
2300
2352
|
|
|
2301
2353
|
// 2. Extract global flag tokens
|
|
2302
2354
|
const allFlagParams = allFlags.flatMap((f) => Param.extractSingleParams(f.flag))
|
|
@@ -2311,8 +2363,8 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
|
|
|
2311
2363
|
// 3. Parse command arguments from remaining tokens
|
|
2312
2364
|
const parsedArgs = yield* Parser.parseArgs({ tokens: remainder, trailingOperands }, command)
|
|
2313
2365
|
const commandPath = [command.name, ...Parser.getCommandPath(parsedArgs)] as const
|
|
2314
|
-
const handlerCtx: GlobalFlag.HandlerContext = { command, commandPath, version: config.version }
|
|
2315
|
-
const activeFlags = getGlobalFlagsForCommandPath(command, commandPath,
|
|
2366
|
+
const handlerCtx: GlobalFlag.HandlerContext = { builtIns, command, commandPath, version: config.version }
|
|
2367
|
+
const activeFlags = getGlobalFlagsForCommandPath(command, commandPath, builtIns)
|
|
2316
2368
|
|
|
2317
2369
|
// 4. Reject globals that were passed outside the active command scope
|
|
2318
2370
|
const outOfScopeErrors = getOutOfScopeGlobalFlagErrors(allFlags, activeFlags, flagMap, commandPath)
|
|
@@ -2334,6 +2386,29 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
|
|
|
2334
2386
|
})
|
|
2335
2387
|
if (!hasEntry) continue
|
|
2336
2388
|
const [, value] = yield* flag.flag.parse(emptyArgs)
|
|
2389
|
+
if (flag === GlobalFlag.Wizard) {
|
|
2390
|
+
return yield* Effect.gen(function*() {
|
|
2391
|
+
yield* Console.log(Wizard.renderIntroduction(command.name, config.version, command.description))
|
|
2392
|
+
const prefix = [
|
|
2393
|
+
command.name,
|
|
2394
|
+
...args.filter((arg) => arg !== "--wizard" && !arg.startsWith("--wizard="))
|
|
2395
|
+
]
|
|
2396
|
+
const wizardArgs = yield* Wizard.run(command, { commandPath, prefix })
|
|
2397
|
+
yield* Console.log(Wizard.renderCompletion(wizardArgs))
|
|
2398
|
+
const shouldRun = yield* Prompt.run(Prompt.toggle({
|
|
2399
|
+
message: "Run this command?",
|
|
2400
|
+
initial: true,
|
|
2401
|
+
active: "yes",
|
|
2402
|
+
inactive: "no"
|
|
2403
|
+
}))
|
|
2404
|
+
if (shouldRun) {
|
|
2405
|
+
yield* Console.log()
|
|
2406
|
+
yield* runWith(command, config)(wizardArgs.slice(1))
|
|
2407
|
+
}
|
|
2408
|
+
}).pipe(
|
|
2409
|
+
Effect.catchTag("QuitError", () => Console.log(Wizard.renderQuit()))
|
|
2410
|
+
)
|
|
2411
|
+
}
|
|
2337
2412
|
yield* flag.run(value, handlerCtx)
|
|
2338
2413
|
return
|
|
2339
2414
|
}
|
|
@@ -2352,15 +2427,16 @@ export const runWith = <const Name extends string, Input, E, R, ContextInput>(
|
|
|
2352
2427
|
|
|
2353
2428
|
// 7. Provide setting values
|
|
2354
2429
|
let program = commandImpl.handle(parseResult.success, [command.name])
|
|
2430
|
+
const logLevel = activeFlags.includes(GlobalFlag.LogLevel)
|
|
2431
|
+
? (yield* GlobalFlag.LogLevel.flag.parse(emptyArgs))[1]
|
|
2432
|
+
: Option.none()
|
|
2433
|
+
program = Effect.provideService(program, GlobalFlag.LogLevel, logLevel)
|
|
2355
2434
|
for (const flag of activeFlags) {
|
|
2356
|
-
if (flag._tag !== "Setting") continue
|
|
2435
|
+
if (flag._tag !== "Setting" || flag === GlobalFlag.LogLevel) continue
|
|
2357
2436
|
const [, value] = yield* flag.flag.parse(emptyArgs)
|
|
2358
2437
|
program = Effect.provideService(program, flag, value)
|
|
2359
2438
|
}
|
|
2360
2439
|
|
|
2361
|
-
const [, logLevel] = yield* GlobalFlag.LogLevel.flag.parse(emptyArgs)
|
|
2362
|
-
program = Effect.provideService(program, GlobalFlag.LogLevel, logLevel)
|
|
2363
|
-
|
|
2364
2440
|
// 8. Apply built-in setting behavior
|
|
2365
2441
|
const services = Option.match(logLevel, {
|
|
2366
2442
|
onNone: () => Context.empty(),
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This module defines two kinds of global flags: action flags, which run an
|
|
6
6
|
* effect and stop normal command execution, and setting flags, which provide a
|
|
7
7
|
* parsed value to the command handler through the Effect context. It also
|
|
8
|
-
* defines the built-in help, version, shell-completion, and log-level flags
|
|
8
|
+
* defines the built-in help, version, wizard, shell-completion, and log-level flags
|
|
9
9
|
* used by `Command.run` and `Command.runWith`.
|
|
10
10
|
*
|
|
11
11
|
* @since 4.0.0
|
|
@@ -37,6 +37,7 @@ export interface HandlerContext {
|
|
|
37
37
|
readonly command: Command.Command.Any
|
|
38
38
|
readonly commandPath: ReadonlyArray<string>
|
|
39
39
|
readonly version: string
|
|
40
|
+
readonly builtIns: ReadonlyArray<BuiltIn>
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/**
|
|
@@ -156,12 +157,11 @@ export const Help: Action<boolean> = action({
|
|
|
156
157
|
Flag.withAlias("h"),
|
|
157
158
|
Flag.withDescription("Show help information")
|
|
158
159
|
),
|
|
159
|
-
run: (_, { command, commandPath })
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
})
|
|
160
|
+
run: Effect.fnUntraced(function*(_, { builtIns, command, commandPath }) {
|
|
161
|
+
const formatter = yield* CliOutput.Formatter
|
|
162
|
+
const helpDoc = yield* HelpInternal.getHelpForCommandPath(command, commandPath, builtIns)
|
|
163
|
+
yield* Console.log(formatter.formatHelpDoc(helpDoc))
|
|
164
|
+
})
|
|
165
165
|
})
|
|
166
166
|
|
|
167
167
|
/**
|
|
@@ -179,11 +179,28 @@ export const Version: Action<boolean> = action({
|
|
|
179
179
|
Flag.withAlias("v"),
|
|
180
180
|
Flag.withDescription("Show version information")
|
|
181
181
|
),
|
|
182
|
-
run: (_, { command, version })
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
run: Effect.fnUntraced(function*(_, { command, version }) {
|
|
183
|
+
const formatter = yield* CliOutput.Formatter
|
|
184
|
+
yield* Console.log(formatter.formatVersion(command.name, version))
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Defines the global action flag for starting interactive wizard mode.
|
|
190
|
+
*
|
|
191
|
+
* **Details**
|
|
192
|
+
*
|
|
193
|
+
* `Command.run` and `Command.runWith` handle this action specially so the
|
|
194
|
+
* generated arguments can be passed back through the command parser.
|
|
195
|
+
*
|
|
196
|
+
* @category references
|
|
197
|
+
* @since 4.0.0
|
|
198
|
+
*/
|
|
199
|
+
export const Wizard: Action<boolean> = action({
|
|
200
|
+
flag: Flag.boolean("wizard").pipe(
|
|
201
|
+
Flag.withDescription("Start wizard mode for a command")
|
|
202
|
+
),
|
|
203
|
+
run: () => Effect.void
|
|
187
204
|
})
|
|
188
205
|
|
|
189
206
|
/**
|
|
@@ -206,14 +223,13 @@ export const Completions: Action<Option.Option<"bash" | "zsh" | "fish">> = actio
|
|
|
206
223
|
Flag.withMetavar("<bash|zsh|fish|sh>"),
|
|
207
224
|
Flag.withDescription("Print shell completion script")
|
|
208
225
|
),
|
|
209
|
-
run: (shell, { command })
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
})
|
|
226
|
+
run: Effect.fnUntraced(function*(shell, { command }) {
|
|
227
|
+
if (Option.isNone(shell)) return
|
|
228
|
+
const descriptor = CommandDescriptor.fromCommand(command)
|
|
229
|
+
yield* Console.log(
|
|
230
|
+
Completions_.generate(command.name, shell.value, descriptor)
|
|
231
|
+
)
|
|
232
|
+
})
|
|
217
233
|
})
|
|
218
234
|
|
|
219
235
|
/**
|
|
@@ -262,7 +278,7 @@ export const LogLevel: Setting<"log-level", Option.Option<LogLevelType>> = setti
|
|
|
262
278
|
*
|
|
263
279
|
* **Details**
|
|
264
280
|
*
|
|
265
|
-
* The built-ins are `Help`, `Version`, `Completions`, and `LogLevel`.
|
|
281
|
+
* The built-ins are `Help`, `Version`, `Wizard`, `Completions`, and `LogLevel`.
|
|
266
282
|
* `Command.runWith` prepends these built-ins when collecting and parsing global
|
|
267
283
|
* flags.
|
|
268
284
|
*
|
|
@@ -279,17 +295,18 @@ export const LogLevel: Setting<"log-level", Option.Option<LogLevelType>> = setti
|
|
|
279
295
|
* @category references
|
|
280
296
|
* @since 4.0.0
|
|
281
297
|
*/
|
|
282
|
-
export const BuiltIns:
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
298
|
+
export const BuiltIns: readonly [
|
|
299
|
+
Action<boolean>,
|
|
300
|
+
Action<boolean>,
|
|
301
|
+
Action<boolean>,
|
|
302
|
+
Action<Option.Option<"bash" | "zsh" | "fish">>,
|
|
303
|
+
Setting<"log-level", Option.Option<LogLevelType>>
|
|
304
|
+
] = [Help, Version, Wizard, Completions, LogLevel]
|
|
288
305
|
|
|
289
306
|
/**
|
|
290
|
-
*
|
|
307
|
+
* Global flag included in the default command-runner configuration.
|
|
291
308
|
*
|
|
292
309
|
* @category models
|
|
293
310
|
* @since 4.0.0
|
|
294
311
|
*/
|
|
295
|
-
export type
|
|
312
|
+
export type BuiltIn = typeof BuiltIns[number]
|