mod status;
#[cfg(test)]
mod tests;
use std::{ffi::OsStr, path::Path, process::Command};
pub use status::{InstallationStatusError, decode_installation_status};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CallMode {
Query,
Update,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CallArguments<'a> {
Text(&'a OsStr),
BinaryFile(&'a Path),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StatusOutput {
Text,
Json,
IdOnly,
}
#[must_use]
pub fn call_command(
mut command: Command,
canister: &OsStr,
method: &OsStr,
arguments: CallArguments<'_>,
mode: CallMode,
) -> Command {
command.args([OsStr::new("canister"), OsStr::new("call"), canister, method]);
match arguments {
CallArguments::Text(argument) => {
command.arg(argument);
}
CallArguments::BinaryFile(path) => {
command
.arg("--args-file")
.arg(path)
.args(["--args-format", "bin"]);
}
}
if mode == CallMode::Query {
command.arg("--query");
}
command
}
#[must_use]
pub fn status_command(mut command: Command, canister: &OsStr, output: StatusOutput) -> Command {
command.args([OsStr::new("canister"), OsStr::new("status"), canister]);
match output {
StatusOutput::Text => {}
StatusOutput::Json => {
command.arg("--json");
}
StatusOutput::IdOnly => {
command.arg("--id-only");
}
}
command
}