Skip to content

Commit

Permalink
Added barebones update command
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Apr 24, 2023
1 parent d46200c commit 21db59a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rye/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod lock;
mod pin;
mod remove;
mod run;
mod rye;
mod shim;
mod show;
mod sync;
Expand All @@ -34,6 +35,8 @@ enum Command {
Show(show::Args),
Sync(sync::Args),
Toolchain(toolchain::Args),
#[command(name = "self")]
Rye(rye::Args),
Uninstall(uninstall::Args),
}

Expand All @@ -55,6 +58,7 @@ pub fn execute() -> Result<(), Error> {
Command::Show(cmd) => show::execute(cmd),
Command::Sync(cmd) => sync::execute(cmd),
Command::Toolchain(cmd) => toolchain::execute(cmd),
Command::Rye(cmd) => rye::execute(cmd),
Command::Uninstall(cmd) => uninstall::execute(cmd),
}
}
62 changes: 62 additions & 0 deletions rye/src/cli/rye.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::process::Command;

use anyhow::{bail, Context, Error};
use clap::Parser;

/// Rye self management
#[derive(Parser, Debug)]
pub struct Args {
#[command(subcommand)]
command: SubCommand,
}

/// Performs an update of rye.
///
/// This currently just is an alias to running cargo install again with the
/// right arguments.
#[derive(Parser, Debug)]
pub struct UpdateCommand {
/// Update to a specific tag.
#[arg(long)]
tag: Option<String>,
/// Update to a specific git rev.
#[arg(long, conflicts_with = "tag")]
rev: Option<String>,
/// Force reinstallation
#[arg(long)]
force: bool,
}

#[derive(Parser, Debug)]
enum SubCommand {
Update(UpdateCommand),
}

pub fn execute(cmd: Args) -> Result<(), Error> {
match cmd.command {
SubCommand::Update(args) => update(args),
}
}

fn update(args: UpdateCommand) -> Result<(), Error> {
let mut cmd = Command::new("cargo");
cmd.arg("install")
.arg("--git")
.arg("https://github.com/mitsuhiko/rye");
if let Some(ref rev) = args.rev {
cmd.arg("--rev");
cmd.arg(rev);
} else if let Some(ref tag) = args.tag {
cmd.arg("--tag");
cmd.arg(tag);
}
if args.force {
cmd.arg("--force");
}
cmd.arg("rye");
let status = cmd.status().context("unable to update via cargo-install")?;
if !status.success() {
bail!("failed to self-update via cargo-install");
}
Ok(())
}

0 comments on commit 21db59a

Please sign in to comment.