GlobalFlag.ts
GlobalFlag.ts overview
Section titled “GlobalFlag.ts overview”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 v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”action
Section titled “action”Creates an Action flag that performs a side effect and exits.
Signature
declare const action: <A>(options: { readonly flag: Flag.Flag<A> readonly run: (value: A, context: HandlerContext) => Effect.Effect<void>}) => Action<A>Since v4.0.0
setting
Section titled “setting”Creates a Setting flag that configures the command handler’s environment.
Signature
declare const setting: <const Id extends string>( id: Id) => <A>(options: { readonly flag: Flag.Flag<A> }) => Setting<Id, A>Since v4.0.0
models
Section titled “models”Action (interface)
Section titled “Action (interface)”Action flag: side effect + exit (–help, –version, –completions).
Signature
export interface Action<A> { readonly _tag: "Action" readonly flag: Flag.Flag<A> readonly run: (value: A, context: HandlerContext) => Effect.Effect<void>}Since v4.0.0
BuiltInSettingContext (type alias)
Section titled “BuiltInSettingContext (type alias)”Built-in setting context identifiers.
Signature
type BuiltInSettingContext = Setting.Identifier<"log-level">Since v4.0.0
GlobalFlag (type alias)
Section titled “GlobalFlag (type alias)”Global flag discriminated union.
Signature
type GlobalFlag<A> = Action<A> | Setting<any, A>Since v4.0.0
HandlerContext (interface)
Section titled “HandlerContext (interface)”Context passed to action handlers.
Signature
export interface HandlerContext { readonly command: Command.Command.Any readonly commandPath: ReadonlyArray<string> readonly version: string}Since v4.0.0
Setting (interface)
Section titled “Setting (interface)”Setting flag: configure command handler’s environment (–log-level, –config).
Signature
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>}Since v4.0.0
references
Section titled “references”BuiltIns
Section titled “BuiltIns”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
Helpfor the help action flagVersionfor the version action flagCompletionsfor the shell-completions action flagLogLevelfor the built-in log-level setting flag
Signature
declare const BuiltIns: ReadonlyArray<GlobalFlag<any>>Since v4.0.0
Completions
Section titled “Completions”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.
Signature
declare const Completions: Action<Option.Option<"bash" | "zsh" | "fish">>Since v4.0.0
Defines the --help / -h global flag, which shows help documentation for the
active command path.
See
BuiltInsfor the default list containing this flagactionfor defining custom action global flags
Signature
declare const Help: Action<boolean>Since v4.0.0
LogLevel
Section titled “LogLevel”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.
Signature
declare const LogLevel: Setting<"log-level", Option.Option<LogLevelType>>Since v4.0.0
Version
Section titled “Version”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.
Signature
declare const Version: Action<boolean>Since v4.0.0
Setting (namespace)
Section titled “Setting (namespace)”Namespace containing type helpers for global setting flags.
Since v4.0.0
Identifier (type alias)
Section titled “Identifier (type alias)”Type-level service identifier used by Setting global flags for the
parsed value associated with a setting id.
Signature
type`effect/unstable/cli/GlobalFlag/${Id}` = `effect/unstable/cli/GlobalFlag/${Id}`Since v4.0.0