1/**
2 * Configuration for Effect CLI command execution.
3 *
4 * @stability unstable
5 * @since 4.0.0
6 */
7import * as Context from "../Context.ts"
8import * as Layer from "../Layer.ts"
9import * as GlobalFlag from "./GlobalFlag.ts"
10
11/**
12 * Context reference for configuration shared by CLI parsing, help generation,
13 * and command execution.
14 *
15 * **When to use**
16 *
17 * Use when you need to customize runner-wide CLI behavior, such as which
18 * built-in global flags are available.
19 *
20 * @stability unstable
21 * @category services
22 * @since 4.0.0
23 */
24export class CliConfig extends Context.Reference<CliConfig.Service>("effect/cli/CliConfig", {
25 defaultValue: () => defaults
26}) {}
27
28/**
29 * Types used by the `CliConfig` context reference.
30 *
31 * @stability unstable
32 * @since 4.0.0
33 */
34export declare namespace CliConfig {
35 /**
36 * Configuration values used while running a CLI command.
37 *
38 * @stability unstable
39 * @category models
40 * @since 4.0.0
41 */
42 export interface Service {
43 /** Ordered built-in global flags, with earlier action flags taking precedence. */
44 readonly builtIns: ReadonlyArray<GlobalFlag.BuiltIn>
45 }
46}
47
48/**
49 * Default CLI configuration containing every built-in global flag.
50 *
51 * @stability unstable
52 * @category defaults
53 * @since 4.0.0
54 */
55export const defaults: CliConfig.Service = {
56 builtIns: GlobalFlag.BuiltIns
57}
58
59/**
60 * Creates CLI configuration by merging the provided options over `defaults`.
61 *
62 * **When to use**
63 *
64 * Use when you need a configuration value to provide directly through the
65 * `CliConfig` context reference.
66 *
67 * @see {@link layer} for providing configuration as a layer
68 *
69 * @stability unstable
70 * @category constructors
71 * @since 4.0.0
72 */
73export const make = (options?: Partial<CliConfig.Service>): CliConfig.Service => ({
74 ...defaults,
75 ...options
76})
77
78/**
79 * Creates a layer that provides CLI configuration merged over `defaults`.
80 *
81 * **When to use**
82 *
83 * Use when wiring customized CLI behavior into an application layer.
84 *
85 * @see {@link make} for creating a configuration value directly
86 *
87 * @stability unstable
88 * @category layers
89 * @since 4.0.0
90 */
91export const layer = (options?: Partial<CliConfig.Service>): Layer.Layer<never> =>
92 Layer.succeed(CliConfig, make(options))