fix(json-edit): with actual arg instead of stupid str replace
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
2919ca9a04
commit
56b44cf2e2
@ -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()
|
||||||
|
@ -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();
|
||||||
|
Loading…
Reference in New Issue
Block a user