Skip to content

Commit

Permalink
Shorten --argjson handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Jan 14, 2025
1 parent 08ac834 commit 5cea749
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions jaq/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ fn binds(cli: &Cli) -> Result<Vec<(String, Val)>, Error> {
let argjson = cli.argjson.iter().map(|(k, s)| {
use hifijson::token::Lex;
let mut lexer = hifijson::SliceLexer::new(s.as_bytes());
let v = lexer
.exactly_one(Val::parse)
.map_err(|e| Error::Parse(format!("{e} (for value passed to `--argjson {k}`)")));
Ok((k.to_owned(), v?))
let err = |e| Error::Parse(format!("{e} (for value passed to `--argjson {k}`)"));
Ok((k.to_owned(), lexer.exactly_one(Val::parse).map_err(err)?))
});
let rawfile = cli.rawfile.iter().map(|(k, path)| {
let s = std::fs::read_to_string(path).map_err(|e| Error::Io(Some(format!("{path:?}")), e));
Expand Down

0 comments on commit 5cea749

Please sign in to comment.