use anyhow::{Context, Result};
use clap::Parser;
use std::process::Command;
const REPO: &str = "https://github.com/gear-tech/gear-program";
#[derive(Clone, Debug, Parser)]
pub struct Update {
#[arg(short, long)]
pub force: bool,
}
impl Update {
pub async fn exec(self) -> Result<()> {
let args: &[&str] = if self.force {
&["--git", REPO, "--force"]
} else {
&[env!("CARGO_PKG_NAME")]
};
let status = Command::new("cargo")
.args([&["install"], args].concat())
.status()
.context("failed to self-update using `cargo install`")?;
if !status.success() {
std::process::exit(status.code().unwrap_or(1))
}
Ok(())
}
}