Skip to content

Commit

Permalink
feat: add option to enable updating a single tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Mackay committed Aug 22, 2024
1 parent 7927e23 commit 7fb7d93
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// Updates GitHub release artifacts in the specified lockfile
Update,
Update {
/// The tool to update, if unset, all tools are updated.
#[clap(long)]
tool: Option<String>,
},
}

trait Common {
Expand Down Expand Up @@ -179,7 +183,7 @@ fn update_github_release(
})
}

fn update_lockfile(path: &std::path::Path) {
fn update_lockfile(path: &std::path::Path, tool_to_update: &Option<String>) {
let contents = fs::read_to_string(path).expect("Unable to load lockfile");

let lockfile: Lockfile =
Expand All @@ -201,6 +205,13 @@ fn update_lockfile(path: &std::path::Path) {
.tools
.into_iter()
.map(|(tool, binary)| {
if let Some(t) = tool_to_update {
if !t.eq_ignore_ascii_case(&tool) {
// Return the tool definition unchanged if this is not being updated.
return (tool, binary);
}
}

let mut binaries: Vec<Binary> = binary
.binaries
.into_iter()
Expand Down Expand Up @@ -247,6 +258,6 @@ fn main() {
}

match &cli.command {
Commands::Update => update_lockfile(lockfile),
Commands::Update { tool } => update_lockfile(lockfile, tool),
}
}

0 comments on commit 7fb7d93

Please sign in to comment.