Permalink
Browse files

Change wait builtin to use core/args.py, not Python's getopt.

  • Loading branch information...
Andy Chu
Andy Chu committed Jan 24, 2018
1 parent 8dc203a commit ab9a59f50e00be354ff8557f56566f88740d2a24
Showing with 10 additions and 24 deletions.
  1. +10 −24 core/builtin.py
View
@@ -244,8 +244,9 @@ def Echo(argv):
return 0
# TODO: remove getopt
import getopt
WAIT_SPEC = _Register('wait')
WAIT_SPEC.ShortFlag('-n')
def Wait(argv, waiter, job_state, mem):
"""
@@ -271,25 +272,10 @@ def Wait(argv, waiter, job_state, mem):
This is different than a PID? But it does have a PID.
"""
# NOTE: echo can't use getopt because of 'echo ---'
# But that's a special case; the rest of the builtins can use it.
# We must respect -- everywhere, EXCEPT echo. 'wait -- -n' should work must work.
opt_n = False
try:
opts, args = getopt.getopt(argv, 'n')
except getopt.GetoptError as e:
# TODO: Should be args.UsageError()
util.usage(str(e))
return 2
for name, val in opts:
if name == '-n':
opt_n = True
else:
raise AssertionError
arg, i = WAIT_SPEC.Parse(argv)
pids = argv[i:]
if opt_n:
if arg.n:
# wait -n returns the exit status of the process. But how do you know
# WHICH process? That doesn't seem useful.
log('wait next')
@@ -298,7 +284,7 @@ def Wait(argv, waiter, job_state, mem):
else:
return 127 # nothing to wait for
if not args:
if not pids:
log('wait all')
# TODO: get all background jobs from JobState?
i = 0
@@ -317,12 +303,12 @@ def Wait(argv, waiter, job_state, mem):
# code of last one to FINSIH.
status = 1 # error
for a in args:
for pid in pids:
# NOTE: osh doesn't accept 'wait %1' yet
try:
jid = int(a)
jid = int(pid)
except ValueError:
util.error('Invalid argument %r', a)
util.error('Invalid argument %r', pid)
return 127
job = job_state.jobs.get(jid)

0 comments on commit ab9a59f

Please sign in to comment.