///|
/// Start a batteries-included host builder for the application `name` with the
/// command-line arguments `args`. The services record defaults to `Unit` until
/// `@lander.build(factory)` changes it.
///
/// Defaults turned on by `cli`:
/// - Linked configuration formats from `moonrockz/moon-lander-config/formats`
/// (`@lander.formats` narrows them).
/// - Standard application directory conventions `app_dirs(name, prefix~)`
/// (`@lander.conventions` transforms or replaces them).
/// - Standard global discovery flags `--environment`, `--config`, `--isolated`
/// and `--project` (`@lander.no_standard_flags` disables them).
/// - Environment-file discovery without a default name; files load only when
/// `--environment`, `_ENVIRONMENT` or a default sets a name
/// (`@lander.no_environments` disables them).
/// - `_*` environment-variable source at priority 600 and a 30-second
/// shutdown timeout.
///
/// Explicit starting settings replace process inputs. `environment` sets a
/// default name and enables environment-file discovery. Parse the name with
/// `@lander.EnvironmentName::parse` at the caller boundary.
pub fn cli(
name : @lander_core.AppName,
args : Array[String],
env_vars? : &@hosting.IntoEnvVars,
working_dir? : @lander_core.AbsolutePath,
environment? : @conventions.EnvironmentName,
) -> @hosting.HostBuilder[Unit] {
@hosting.builder(name, args, env_vars?, working_dir?, environment?)
|> @hosting.default_formats(@formats.formats())
|> @hosting.app_dirs()
|> @hosting.enable_standard_flags()
|> @hosting.enable_environments()
|> @hosting.with_factory(_ => ())
}
///|
/// Keep only the linked formats whose `Format.name` matches an entry in
/// `names` without regard to ASCII letter case, preserving linked order.
/// An unknown name ends the run before any file read with
/// `HostError::UnknownFormat` and exit code 1, naming the unknown name and the
/// linked format names.
pub fn[S] formats(
builder : @hosting.HostBuilder[S],
names : Array[String],
) -> @hosting.HostBuilder[S] {
@hosting.select_formats(builder, @formats.formats(), names)
}
///|
/// Transform or replace the host-owned convention set. Under `@lander.cli`,
/// `transform` receives the default `app_dirs(name, prefix~)` set.
pub fn[S] conventions(
builder : @hosting.HostBuilder[S],
transform : (@conventions.Conventions) -> @conventions.Conventions,
) -> @hosting.HostBuilder[S] {
@hosting.conventions(builder, transform)
}
///|
/// Turn off the four standard discovery flags (`--environment`, `--config`,
/// `--isolated`, `--project`) on the default root command and pass an empty
/// `StandardFlags` set to `@lander.command`.
pub fn[S] no_standard_flags(
builder : @hosting.HostBuilder[S],
) -> @hosting.HostBuilder[S] {
@hosting.disable_standard_flags(builder)
}
///|
/// Turn off environment-file discovery on the host-owned conventions set.
/// `HostEnvironment.environment_name` still resolves from `--environment`,
/// `_ENVIRONMENT` and any default environment.
pub fn[S] no_environments(
builder : @hosting.HostBuilder[S],
) -> @hosting.HostBuilder[S] {
@hosting.disable_environments(builder)
}
///|
/// Define a custom argparse root command. `make` receives the application name
/// and the active `StandardFlags` (empty when `no_standard_flags()` is set).
/// Use `standard.options()` and `standard.flags()` to include the standard
/// flags, and `standard.without(flag)` to omit any flag that the application
/// defines itself.
pub fn[S] command(
builder : @hosting.HostBuilder[S],
make : (String, @hosting.StandardFlags) -> @argparse.Command,
mappings~ : Array[@hosting.Mapping] = [],
) -> @hosting.HostBuilder[S] {
@hosting.command_with_standard(builder, make, mappings~)
}
///|
/// Set the services record factory for a `@lander` pipeline, changing
/// `HostBuilder[Unit]` to `HostBuilder[S]` while keeping every earlier setting
/// and hosted service. Services registered before `build` keep their order and
/// receive a `Context[Unit]`.
pub fn[S] build(
builder : @hosting.HostBuilder[Unit],
factory : (@hosting.BuildContext) -> S raise,
) -> @hosting.HostBuilder[S] {
@hosting.with_factory(builder, factory)
}
///|
/// Build a services record that implements `Program` and run it with the same
/// target driver selection as `@lander.run`.
pub fn[S : @hosting.Program] run_app(
builder : @hosting.HostBuilder[Unit],
factory : (@hosting.BuildContext) -> S raise,
) -> Unit {
builder |> build(factory) |> run(ctx => S::run(ctx.services, ctx))
}
///|
/// Hosting steps and types re-exported so batteries-included applications can
/// write pipelines in one `@lander` style.
pub using @hosting {
service,
configure,
env_prefix,
reserve_env,
skip_env_source,
env_vars,
working_dir,
default_environment,
content_root,
files,
error_report,
shutdown_timeout,
shutdown_timeout_key,
profiles,
type HostBuilder,
type BuildContext,
type Context,
type HostEnvironment,
type Lifetime,
type StopToken,
type StopReason,
type SignalKind,
type StopRequested,
type UsageError,
type ServiceName,
trait IntoServiceName,
trait IntoEnvVars,
type ExitCode,
type HostError,
type Hook,
type StandardFlag,
type StandardFlags,
trait Program,
}
///|
/// Argparse override mapping helpers re-exported from
/// `moonrockz/moon-lander-hosting/argparse`.
pub using @hosting_argparse {
map,
type Mapping,
type MappingAction,
type OverrideOption,
type MappingError,
}
///|
/// Core domain types re-exported from `moonrockz/moon-lander-core`.
pub using @lander_core {
type AppName,
type AppNameError,
type AppNameRule,
type EnvPrefix,
type AbsolutePath,
type TimeLimit,
}
///|
/// The parsed environment name for the starting default, from
/// `moonrockz/moon-lander-config/conventions`.
pub using @conventions {type EnvironmentName}
///|
/// Parsed profile selection and loaded activation metadata.
pub using @config {
type ProfileName,
type ProfileNames,
type ProfileSelection,
type ProfileState,
type ProfileResolution,
}
///|
/// The opt-in profile policy used by `@lander.profiles`.
pub using @profiles {type Policy}