# step-cargo-check.ncl — reusable ActionStep template for cargo check/clippy/test.
#
# Usage in a mode:
#   let t = import "../../reflection/templates/step-cargo-check.ncl" in
#   steps = [
#     t { id = "clippy", subcommand = "clippy", extra_flags = "-- -D warnings" },
#     t { id = "test", subcommand = "test", package = "ontoref-ontology" },
#   ]
#
# Required params: id (String)
# Optional params: subcommand (default "check"), package, extra_flags, action, actor, depends_on, on_error

fun params =>
  let defaults = {
    subcommand  | default = "check",
    package     | default = "",
    extra_flags | default = "",
    action      | default = "Run cargo to validate Rust code integrity.",
    actor       | default = 'Both,
    depends_on  | default = [],
    on_error    | default = { strategy = 'Stop },
  } in
  let p = defaults & params in
  let pkg_flag =
    if p.package == "" then ""
    else " -p %{p.package}"
  in
  let flags =
    if p.extra_flags == "" then ""
    else " %{p.extra_flags}"
  in
  {
    id         = p.id,
    action     = p.action,
    cmd        = "cargo %{p.subcommand}%{pkg_flag}%{flags}",
    actor      = p.actor,
    depends_on = p.depends_on,
    on_error   = p.on_error,
  }
