Skip to content

Commit

Permalink
Readability and brevity improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Jul 7, 2017
1 parent e4d0ac4 commit ed80ca3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_yq(self):
self.assertEqual(self.run_yq("- понедельник\n- вторник\n", ["-y", "."]), "- понедельник\n- вторник\n")

def test_yq_err(self):
err = 'yq: Error while running jq: ScannerError: while scanning for the next token\nfound character \'%\' that cannot start any token\n in "<file>", line 1, column 3.'
err = 'yq: Error running jq: ScannerError: while scanning for the next token\nfound character \'%\' that cannot start any token\n in "<file>", line 1, column 3.'
self.run_yq("- %", ["."], expect_exit_code=err)

def test_datetimes(self):
Expand Down
6 changes: 4 additions & 2 deletions yq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ def main(args=None):
args, jq_args = parser.parse_known_args(args=args)
if sys.stdin.isatty() and not args.file:
return parser.print_help()

try:
# Note: universal_newlines is just a way to induce subprocess to make stdin a text buffer and encode it for us
jq = subprocess.Popen(["jq"] + jq_args + [args.jq_filter],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE if args.yaml_output else None,
universal_newlines=True)
except OSError as e:
msg = "yq: Error while starting jq: {}: {}. Is jq installed and available on PATH?"
msg = "yq: Error starting jq: {}: {}. Is jq installed and available on PATH?"
parser.exit(msg.format(type(e).__name__, e))

try:
input_stream = args.file[0] if args.file else sys.stdin
if args.yaml_output:
Expand All @@ -78,4 +80,4 @@ def main(args=None):
input_stream.close()
exit(jq.returncode)
except Exception as e:
parser.exit("yq: Error while running jq: {}: {}.".format(type(e).__name__, e))
parser.exit("yq: Error running jq: {}: {}.".format(type(e).__name__, e))

0 comments on commit ed80ca3

Please sign in to comment.