Compare commits

..

2 Commits

Author SHA1 Message Date
NotAFile 0fc052efe0 add more possible todos 2021-09-29 18:01:12 +02:00
NotAFile 750c8d3e28 add non-raw jq option 2021-09-29 17:37:36 +02:00
2 changed files with 17 additions and 4 deletions

View File

@ -44,6 +44,13 @@ if __name__ == "__main__":
- [ ] xargs (only prints)
- [x] shell commands (no stderr capture)
- [x] jq via bindings
- [ ] grep
- [ ] head/tail
- [ ] sort
- [ ] basic shell loops
- [ ] shell globs
- [ ] file operations (mv, cp, rm, ls)
- [ ] cat
- [ ] sed
- [ ] trim
- [ ] subshell

View File

@ -98,10 +98,16 @@ class JqMapper(AbstractMapper):
return ["json", "bytes"]
def generate(self, input_name: str, output_formats: List[str]) -> ShellMapping:
if self._parsed.raw_output:
# TODO: remove join hack with proper datatype analysis
code = dedent(f"""\
filtered = "\\n".join(jq.all({self._parsed.filter!r}, text={input_name}))
""")
else:
code = dedent(f"""\
filtered = jq.text({self._parsed.filter!r}, text={input_name})
""")
return ShellMapping(code=code, output_name="filtered", output_format="str", input_format="", imports=["import jq"])