Skip to content
Permalink
Browse files

Merge pull request #509 from modcloth/mbh/implement-p-flag

Implementing the "-p" flag
  • Loading branch information
alex committed Mar 15, 2013
2 parents 7f80877 + 4cadfec commit b2295ebac65f6e174fdf5d6d8a8b9ce85898ca93
Showing with 8 additions and 4 deletions.
  1. +0 −2 spec/tags/command_line/dash_p_tags.txt
  2. +8 −2 topaz/main.py

This file was deleted.

@@ -25,7 +25,7 @@
""" -Idirectory specify $LOAD_PATH directory (may be used more than once)""",
# """ -l enable line ending processing""",
""" -n assume 'while gets(); ... end' loop around your script""",
# """ -p assume loop like -n but print line also like sed""",
""" -p assume loop like -n but print line also like sed""",
""" -rlibrary require the library, before executing your script""",
""" -s enable some switch parsing for switches after script name""",
""" -S look for the script using PATH environment variable""",
@@ -134,6 +134,9 @@ def _parse_argv(space, argv):
globalize_switches = True
elif arg == "-n":
do_loop = True
elif arg == "-p":
do_loop = True
flag_globals_w["$-p"] = space.w_true
elif arg == "--":
idx += 1
break
@@ -278,14 +281,17 @@ def _entry_point(space, argv):
explicit_status = False
try:
if do_loop:
print_after = space.is_true(flag_globals_w["$-p"])
bc = space.compile(source, path)
frame = space.create_frame(bc)
while True:
w_line = space.send(space.w_kernel, space.newsymbol("gets"))
if w_line is space.w_nil:
break
with space.getexecutioncontext().visit_frame(frame):
space.execute_frame(frame, bc)
w_res = space.execute_frame(frame, bc)
if print_after:
space.send(space.w_kernel, space.newsymbol("print"), [w_res])
else:
space.execute(source, filepath=path)
except RubyError as e:

0 comments on commit b2295eb

Please sign in to comment.
You can’t perform that action at this time.