Skip to content

Commit ce81570

Browse files
committed
refactor: de-deduplicate steampipe matcher logic
1 parent 755df3d commit ce81570

File tree

1 file changed

+20
-24
lines changed
  • postgresql_extensions/src/repository/steampipe

1 file changed

+20
-24
lines changed

postgresql_extensions/src/repository/steampipe/matcher.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,27 @@ pub fn matcher(url: &str, name: &str, _version: &Version) -> Result<bool> {
2424
if !name.starts_with("steampipe_postgres_") {
2525
return Ok(false);
2626
}
27-
let os = match consts::OS {
27+
let os = get_os();
28+
let arch = get_arch();
29+
let suffix = format!(".pg{postgresql_version}.{os}_{arch}.tar.gz");
30+
Ok(name.ends_with(suffix.as_str()))
31+
}
32+
33+
/// Get the OS name for the Steampipe binary.
34+
fn get_os() -> &'static str {
35+
match consts::OS {
2836
"macos" => "darwin",
2937
_ => "linux",
30-
};
31-
let arch = match consts::ARCH {
38+
}
39+
}
40+
41+
/// Get the architecture name for the Steampipe binary.
42+
fn get_arch() -> &'static str {
43+
match consts::ARCH {
3244
"x86_64" => "amd64",
3345
"aarch64" => "arm64",
3446
_ => consts::ARCH,
35-
};
36-
let suffix = format!(".pg{postgresql_version}.{os}_{arch}.tar.gz");
37-
Ok(name.ends_with(suffix.as_str()))
47+
}
3848
}
3949

4050
#[cfg(test)]
@@ -50,15 +60,8 @@ mod tests {
5060
steampipe::URL
5161
);
5262
let version = Version::parse("0.12.0")?;
53-
let os = match consts::OS {
54-
"macos" => "darwin",
55-
_ => "linux",
56-
};
57-
let arch = match consts::ARCH {
58-
"x86_64" => "amd64",
59-
"aarch64" => "arm64",
60-
_ => consts::ARCH,
61-
};
63+
let os = get_os();
64+
let arch = get_arch();
6265
let name =
6366
format!("steampipe_postgres_csv.pg{postgresql_major_version}.{os}_{arch}.tar.gz");
6467

@@ -93,15 +96,8 @@ mod tests {
9396
steampipe::URL
9497
);
9598
let version = Version::parse("0.12.0")?;
96-
let os = match consts::OS {
97-
"macos" => "darwin",
98-
_ => "linux",
99-
};
100-
let arch = match consts::ARCH {
101-
"x86_64" => "amd64",
102-
"aarch64" => "arm64",
103-
_ => consts::ARCH,
104-
};
99+
let os = get_os();
100+
let arch = get_arch();
105101
let names = vec![
106102
format!("foo_csv.pg{postgresql_major_version}.{os}_{arch}.tar.gz"),
107103
format!("steampipe_postgres_csv.pg.{os}_{arch}.tar.gz"),

0 commit comments

Comments
 (0)