apenwarr-redo/redo-whichdo.py
Avery Pennarun 2a936a7574 Print a nicer error message when asked to build an empty string ('').
This happens sometimes, for example, if you do
	whatever | while read x; do
		redo-ifchange "$x"
	done
and the input contains blank lines.

We could ignore the request for blankness, but it seems like that
situation might indicate a more serious bug in your parser, so it's
probably better to just abort with a meaningful error.
2018-11-03 22:02:26 -04:00

28 lines
683 B
Python
Executable file

#!/usr/bin/env python
import sys, os
import vars_init
vars_init.init_no_state()
import paths
from log import err
if len(sys.argv[1:]) != 1:
err('%s: exactly one argument expected.\n' % sys.argv[0])
sys.exit(1)
want = sys.argv[1]
if not want:
err('cannot build the empty target ("").\n')
sys.exit(204)
abswant = os.path.abspath(want)
for dodir,dofile,basedir,basename,ext in paths.possible_do_files(abswant):
dopath = os.path.join('/', dodir, dofile)
relpath = os.path.relpath(dopath, '.')
exists = os.path.exists(dopath)
assert('\n' not in relpath)
print relpath
if exists:
sys.exit(0)
sys.exit(1) # no appropriate dofile found