Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cargo-shuttle): Add upgrade subcommand to run install script #1848

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub enum Command {
Generate(GenerateCommand),
/// Open an issue on GitHub and provide feedback
Feedback,
/// Upgrade the cargo-shuttle binary
Upgrade,
}

#[derive(Parser)]
Expand Down
25 changes: 25 additions & 0 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ impl Shuttle {
ProjectCommand::Stop => self.project_stop().await,
ProjectCommand::Delete(ConfirmationArgs { yes }) => self.project_delete(yes).await,
},
Command::Upgrade => update_cargo_shuttle().await,
};

for w in self.version_warnings {
Expand Down Expand Up @@ -2965,6 +2966,30 @@ pub enum CommandOutcome {
DeploymentFailure,
}

async fn update_cargo_shuttle() -> Result<CommandOutcome> {
#[cfg(target_family = "unix")]
let _ = tokio::process::Command::new("bash")
.args(["-c", "curl -sSfL https://www.shuttle.rs/install | bash"])
.kill_on_drop(true)
.spawn()
.context("Failed to spawn bash update process")?
.wait()
.await
.context("Failed to wait on bash update process")?;

#[cfg(target_family = "windows")]
let _ = tokio::process::Command::new("powershell")
.args(["-Command", "iwr https://www.shuttle.rs/install-win | iex"])
.kill_on_drop(true)
.spawn()
.context("Failed to spawn powershell update process")?
.wait()
.await
.context("Failed to wait on powershell update process")?;

Ok(CommandOutcome::Ok)
}

#[cfg(test)]
mod tests {
use flate2::read::GzDecoder;
Expand Down