def parse(f: IO[Any]) -> Result:
"""
Parse a shellscript and return a ShellScript
:param f: TextIOBase handle to the shellscript file
:return: Result with Ok or Err
"""
comments = []
commands = []
interpreter = ""
buf = f.readlines()
for line in buf:
trimmed = line.strip()
if trimmed.startswith("#!"):
interpreter = trimmed
elif trimmed.startswith("#"):
comments.append(str(trimmed))
else:
# Skip blank lines
if trimmed:
commands.append(str(trimmed))
return Ok(ShellScript(interpreter=interpreter,
comments=comments,
commands=commands))
评论列表
文章目录