Skip to content

Commit

Permalink
Merge pull request #19 from clux/allow-empty-query
Browse files Browse the repository at this point in the history
Allow eliding the jq_query
  • Loading branch information
clux authored Sep 19, 2023
2 parents cca6da6 + d1bbc70 commit 243fd21
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion test/yq.test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
skip # ci is fun
fi
run yq
[ "$status" -eq 2 ]
[ "$status" -eq 1 ]
}

@test "toml" {
Expand Down Expand Up @@ -87,3 +87,10 @@
run yq 'include "k"; . | gvk' -r -L$PWD/test/modules < test/grafana.yaml
echo "$output" && echo "$output" | grep 'apps/v1.Deployment'
}

@test "paramless" {
run yq -y <<< '["foo"]'
echo "$output" && echo "$output" | grep '\- foo'
run yq <<< '"bar"'
echo "$output" && echo "$output" | grep '"bar"'
}
11 changes: 8 additions & 3 deletions yq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ struct Args {
in_place: bool,

/// Query to be sent to jq (see https://jqlang.github.io/jq/manual/)
///
/// Default "."
#[arg()]
jq_query: String,
jq_query: Option<String>,

/// Optional file to read (instead of stdin) in the chosen --input format
#[arg()]
Expand Down Expand Up @@ -105,7 +107,10 @@ struct Args {

impl Args {
fn jq_args(&self) -> Vec<String> {
let mut args = vec![self.jq_query.clone()];
let mut args = vec![];
if let Some(query) = &self.jq_query {
args.push(query.into())
}
if self.compact_output {
args.push("-c".into());
}
Expand Down Expand Up @@ -292,7 +297,7 @@ mod test {
fn file_input_both_outputs() -> Result<()> {
init_env_tracing_stderr()?;
let mut args = Args {
jq_query: ".[2].metadata".into(),
jq_query: Some(".[2].metadata".into()),
compact_output: true,
output: Output::Jq,
file: Some("test/deploy.yaml".into()),
Expand Down

0 comments on commit 243fd21

Please sign in to comment.