Skip to content

Commit

Permalink
Allow not passing a query string (for unfiltered)
Browse files Browse the repository at this point in the history
`cat json | yq` worked with python-yq by defaulting the filter to '.'

to be able to hotswap we should allow this also

Signed-off-by: clux <[email protected]>
  • Loading branch information
clux committed Sep 19, 2023
1 parent cca6da6 commit 34d0e8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 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
8 changes: 5 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,7 @@ struct Args {

impl Args {
fn jq_args(&self) -> Vec<String> {
let mut args = vec![self.jq_query.clone()];
let mut args = vec![self.jq_query.clone().unwrap_or_else(|| ".".into())];
if self.compact_output {
args.push("-c".into());
}
Expand Down Expand Up @@ -292,7 +294,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 34d0e8f

Please sign in to comment.