Skip to content

Commit

Permalink
Replace all Postgres versions in install command (#842)
Browse files Browse the repository at this point in the history
Use regex::Regex::replace_all to replace all instances of strings like
`postgresql/15` and `pg15`. Fixes an issue where nothing installed and
the trunk ended up with no files and using the version from
`Trunk.toml`.
  • Loading branch information
theory committed Dec 12, 2024
1 parent 1075482 commit 83fa760
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pg-trunk"
version = "0.15.2"
version = "0.15.3"
edition = "2021"
authors = ["Ian Stanton", "Vinícius Miguel"]
description = "A package manager for PostgreSQL extensions"
Expand Down Expand Up @@ -58,6 +58,7 @@ toml = "0.7.2"
which = "4.4.0"
lazy_static = "1.5.0"
fastrand = "2.1.0"
regex = "1.11.1"

[dev-dependencies]
assert_cmd = "2.0.8"
Expand Down
14 changes: 5 additions & 9 deletions cli/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,9 @@ impl SubCommand for BuildCommand {
}

fn process_install_command(install_command: &str, pg_version: u8) -> Cow<'_, str> {
if pg_version == 15 {
Cow::Borrowed(install_command)
} else {
Cow::Owned(
install_command
.replace("postgresql/15/", &format!("postgresql/{pg_version}/"))
.replace("pg15", &format!("pg{pg_version}")),
)
}
// Replace all instances of strings like `postgresql/15` and `pg15`.
let re = regex::Regex::new(r"(postgresql/|pg)\d+").unwrap();
re.replace_all(install_command, |caps: &regex::Captures| -> String {
format!("{}{pg_version}", &caps[1])
})
}

0 comments on commit 83fa760

Please sign in to comment.