use isoloom_manifest::{Action, Run};
use crate::Result;
use crate::error::Error;
use crate::executor::Cx;
use crate::ssh::{self, Login};
use super::state::TfState;
pub(super) fn login(cx: &Cx<'_>, state: &TfState) -> Result<Option<Login>> {
let Some(g) = &cx.run.manifest().guest else { return Ok(None) };
let Run::Action { action: Action::SshRun, with } = &g.status.run else {
return Err(Error::Unsupported {
what: "a guest VM whose status isn't an `ssh.run` step: the runner has no way into it".to_owned(),
});
};
let vars = crate::outputs::with_engine(cx.run.manifest(), &cx.vars, &state.outputs, &state.sensitive);
let arg = |name: &str| vars.with_text(with, "guest.status", name);
let host = arg("host")?;
if host.is_empty() {
return Err(Error::NotRunning {
run: cx.run.name().to_string(),
});
}
Ok(Some(ssh::with_login(cx, &host, arg)?))
}