fix(json-edit): with actual arg instead of stupid str replace
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-08-04 18:56:43 +02:00
parent 2919ca9a04
commit 56b44cf2e2
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 5 additions and 4 deletions

View File

@ -12,8 +12,6 @@ impl JsonEditOptions {
pub fn execute(&self, path: &Path, next_version: impl AsRef<str>) -> anyhow::Result<()> { pub fn execute(&self, path: &Path, next_version: impl AsRef<str>) -> anyhow::Result<()> {
let next_version = next_version.as_ref(); let next_version = next_version.as_ref();
let jq_query = self.jq.replace("%%version%%", next_version);
if !path.exists() { if !path.exists() {
anyhow::bail!("could not find file at: {}", path.display()); anyhow::bail!("could not find file at: {}", path.display());
} }
@ -30,7 +28,10 @@ impl JsonEditOptions {
))?; ))?;
let output = std::process::Command::new("jq") let output = std::process::Command::new("jq")
.arg(format!("{}", jq_query)) .arg("--arg")
.arg("version")
.arg(next_version)
.arg(&self.jq)
.arg( .arg(
abs_path abs_path
.to_str() .to_str()

View File

@ -40,7 +40,7 @@ pub fn test_can_update_version_in_jq() {
pretty_assertions::assert_eq!(initial_content, actual_file); pretty_assertions::assert_eq!(initial_content, actual_file);
let edit_options = JsonEditOptions { let edit_options = JsonEditOptions {
jq: r#".some.nested[].structure.version="%%version%%""#.into(), jq: r#".some.nested[].structure.version=$version"#.into(),
}; };
edit_options.execute(&json_file, "v1.0.2").unwrap(); edit_options.execute(&json_file, "v1.0.2").unwrap();