File size: 5,142 Bytes
31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 689aa9f 31e8457 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | /**
* Global flags for Effect CLI command trees. Global flags are parsed outside a
* single command's local flags and can apply to a command and its descendants.
*
* This module defines two kinds of global flags: action flags, which run an
* effect and stop normal command execution, and setting flags, which provide a
* parsed value to the command handler through the Effect context. It also
* defines the built-in help, version, shell-completion, and log-level flags
* used by `Command.run` and `Command.runWith`.
*
* @since 4.0.0
*/
import * as Context from "../../Context.ts";
import * as Effect from "../../Effect.ts";
import type { LogLevel as LogLevelType } from "../../LogLevel.ts";
import * as Option from "../../Option.ts";
import type * as Command from "./Command.ts";
import * as Flag from "./Flag.ts";
/**
* Context passed to action handlers.
*
* @category models
* @since 4.0.0
*/
export interface HandlerContext {
readonly command: Command.Command.Any;
readonly commandPath: ReadonlyArray<string>;
readonly version: string;
}
/**
* Action flag: side effect + exit (--help, --version, --completions).
*
* @category models
* @since 4.0.0
*/
export interface Action<A> {
readonly _tag: "Action";
readonly flag: Flag.Flag<A>;
readonly run: (value: A, context: HandlerContext) => Effect.Effect<void>;
}
/**
* Setting flag: configure command handler's environment (--log-level, --config).
*
* @category models
* @since 4.0.0
*/
export interface Setting<Id extends string, A> extends Context.Service<Setting.Identifier<Id>, A> {
readonly _tag: "Setting";
readonly id: Id;
readonly flag: Flag.Flag<A>;
}
/**
* Namespace containing type helpers for global setting flags.
*
* @since 4.0.0
*/
export declare namespace Setting {
/**
* Type-level service identifier used by `Setting` global flags for the
* parsed value associated with a setting id.
*
* @category models
* @since 4.0.0
*/
type Identifier<Id extends string> = `effect/unstable/cli/GlobalFlag/${Id}`;
}
/**
* Global flag discriminated union.
*
* @category models
* @since 4.0.0
*/
export type GlobalFlag<A> = Action<A> | Setting<any, A>;
/**
* Creates an Action flag that performs a side effect and exits.
*
* @category constructors
* @since 4.0.0
*/
export declare const action: <A>(options: {
readonly flag: Flag.Flag<A>;
readonly run: (value: A, context: HandlerContext) => Effect.Effect<void>;
}) => Action<A>;
/**
* Creates a Setting flag that configures the command handler's environment.
*
* @category constructors
* @since 4.0.0
*/
export declare const setting: <const Id extends string>(id: Id) => <A>(options: {
readonly flag: Flag.Flag<A>;
}) => Setting<Id, A>;
/**
* Defines the `--help` / `-h` global flag, which shows help documentation for the
* active command path.
*
* @see {@link BuiltIns} for the default list containing this flag
* @see {@link action} for defining custom action global flags
*
* @category references
* @since 4.0.0
*/
export declare const Help: Action<boolean>;
/**
* Defines the global action flag for showing command version information.
*
* **When to use**
*
* Use to add a built-in `--version / -v` flag to a command runner.
*
* @category references
* @since 4.0.0
*/
export declare const Version: Action<boolean>;
/**
* Defines the `--completions` global flag, which prints a shell completion script for
* the given shell.
*
* **Details**
*
* Accepted values are `bash`, `zsh`, `fish`, and `sh`; `sh` is normalized to
* `bash`.
*
* @category references
* @since 4.0.0
*/
export declare const Completions: Action<Option.Option<"bash" | "zsh" | "fish">>;
/**
* Defines the global setting flag for command log level.
*
* **When to use**
*
* Use to add a built-in `--log-level` option that configures the minimum log
* level for the command.
*
* @category references
* @since 4.0.0
*/
export declare const LogLevel: Setting<"log-level", Option.Option<LogLevelType>>;
/**
* Built-in global flags in default precedence order.
*
* **When to use**
*
* Use when extending or inspecting the default global-flag set that
* `Command.runWith` prepends before user-defined global flags.
*
* **Details**
*
* The built-ins are `Help`, `Version`, `Completions`, and `LogLevel`.
* `Command.runWith` prepends these built-ins when collecting and parsing global
* flags.
*
* **Gotchas**
*
* Action flags are processed in active flag order and the first present action
* exits, so this array controls built-in action precedence.
*
* @see {@link Help} for the help action flag
* @see {@link Version} for the version action flag
* @see {@link Completions} for the shell-completions action flag
* @see {@link LogLevel} for the built-in log-level setting flag
*
* @category references
* @since 4.0.0
*/
export declare const BuiltIns: ReadonlyArray<GlobalFlag<any>>;
/**
* Built-in setting context identifiers.
*
* @category models
* @since 4.0.0
*/
export type BuiltInSettingContext = Setting.Identifier<"log-level">;
//# sourceMappingURL=GlobalFlag.d.ts.map |