standard-plugin-cli 0.1.1

standard-plugin: scaffold, build, check and pack Standard Code plugins
Documentation
//! `standard-plugin install`: checks and packs the plugin, then hands the
//! package to `standard plugin install`, which uploads it with the
//! signed-in account's credentials, shows its grants and asks before it
//! installs. This CLI never holds account credentials itself.

use std::path::Path;
use std::process::Command;

/// The command `install` runs.
pub fn command(dir: &Path) -> Command {
    let mut command =
        Command::new(std::env::var_os("STANDARD_BIN").unwrap_or_else(|| "standard".into()));
    command.arg("plugin").arg("install").arg(dir);
    command
}

/// Runs `standard plugin install <dir>` in place of this process (so it
/// can ask y/N on this terminal); returns only when it could not start.
pub fn exec(dir: &Path) -> String {
    let mut command = command(dir);
    println!("running: standard plugin install {}", dir.display());
    #[cfg(unix)]
    {
        use std::os::unix::process::CommandExt as _;
        let error = command.exec();
        format!("could not run `standard` ({error}); install Standard Code or set STANDARD_BIN")
    }
    #[cfg(not(unix))]
    {
        match command.status() {
            Ok(status) if status.success() => String::new(),
            Ok(status) => format!("standard plugin install exited with {status}"),
            Err(error) => format!("could not run `standard` ({error})"),
        }
    }
}