plushie/cargo_plushie

Resolve how to invoke cargo-plushie.

The SDK delegates renderer workspace generation and compilation to cargo-plushie. This module returns the correct way to invoke it:

  1. If PLUSHIE_RUST_SOURCE_PATH is set, invoke via cargo run --manifest-path <source>/Cargo.toml -p cargo-plushie --release --quiet --.
  2. Else if cargo-plushie is on PATH at the matching version, invoke it directly.
  3. Else return an error explaining how to install.

The matching version is the plushie_rust_version declared in the SDK’s gleam.toml (see plushie/config.plushie_rust_version/0), which pins the plushie-rust release this SDK expects.

Types

Concrete command + argument prefix to invoke cargo-plushie.

pub type CargoPlushie {
  CargoPlushie(command: String, args_prefix: List(String))
}

Constructors

  • CargoPlushie(command: String, args_prefix: List(String))

Environment snapshot used by resolve_with.

Threaded explicitly so tests can exercise each path without touching the actual OS environment or PATH.

pub type Environment {
  Environment(
    source_path: Result(String, Nil),
    on_path: Bool,
    path_version_output: Result(String, String),
  )
}

Constructors

  • Environment(
      source_path: Result(String, Nil),
      on_path: Bool,
      path_version_output: Result(String, String),
    )

    Arguments

    source_path

    Value of PLUSHIE_RUST_SOURCE_PATH, if set.

    on_path

    True when cargo-plushie resolves on PATH.

    path_version_output

    Raw output of cargo-plushie --version (only consulted when on_path is True).

Failure modes when resolving how to call cargo-plushie.

pub type ResolveError {
  NotAvailable(expected_version: String)
  VersionMismatch(
    expected_version: String,
    found_version: String,
  )
  UnparseableVersion(raw: String)
}

Constructors

  • NotAvailable(expected_version: String)

    cargo-plushie is not on PATH and PLUSHIE_RUST_SOURCE_PATH is not set.

  • VersionMismatch(expected_version: String, found_version: String)

    cargo-plushie is on PATH but its --version does not match the version the SDK pins.

  • UnparseableVersion(raw: String)

    cargo-plushie --version produced output the SDK could not parse.

Values

pub fn args(
  tool: CargoPlushie,
  subcommand_args: List(String),
) -> List(String)

Just the args (without the executable name) for callers that build Erlang Port specs separately.

pub fn argv(
  tool: CargoPlushie,
  subcommand_args: List(String),
) -> List(String)

Turn a CargoPlushie into the final argv for a subcommand.

pub fn parse_version(raw: String) -> Result(String, Nil)

Extract the semantic version from cargo-plushie --version output.

The tool prints cargo-plushie X.Y.Z (possibly with trailing whitespace). We take the last whitespace-separated token.

pub fn resolve(
  expected_version: String,
) -> Result(CargoPlushie, ResolveError)

Resolve how to invoke cargo-plushie for the given pinned version.

Returns a CargoPlushie value carrying the executable name and any leading args required before the subcommand (e.g. build).

pub fn resolve_error_message(err: ResolveError) -> String

Render ResolveError as a human-readable message.

pub fn resolve_or_message(
  expected_version: String,
) -> Result(CargoPlushie, String)

Convenience wrapper for CLI entry points that want a ready-to-print error message on failure.

pub fn resolve_with(
  expected_version: String,
  env: Environment,
) -> Result(CargoPlushie, ResolveError)

Pure resolver used by resolve/1 and tests. Does not touch the OS.

Search Document