Add some more documentation

This commit is contained in:
Ian Adam Naval 2015-02-26 15:43:26 -05:00
parent 5565f0c4ef
commit 490c9f5900

19
main.py
View File

@ -7,6 +7,8 @@ import os
import os.path import os.path
import shlex import shlex
# Load all of the commands in the path into the global namespace as raw
# commands.
for path in os.environ['PATH'].split(':'): for path in os.environ['PATH'].split(':'):
if os.path.exists(path): if os.path.exists(path):
binaries = os.listdir(path) binaries = os.listdir(path)
@ -34,18 +36,23 @@ def parse_cmd(potential_cmd):
return "{0}({1})".format(cmd_name,str(args)) return "{0}({1})".format(cmd_name,str(args))
def parse_cmds(raw): def parse_cmds(raw_input_line):
potential_cmds = raw.split('|') """Parses command objects out of a single | separated string"""
potential_cmds = raw_input_line.split('|')
cmds = [parse_cmd(cmd) for cmd in potential_cmds] cmds = [parse_cmd(cmd) for cmd in potential_cmds]
return cmds return cmds
def handle_input(prompt=""): def handle_input(prompt=""):
raw = input(prompt) """Gets a single line of input for the REPL, and returns some valid
if raw[0] == '>': Python for the rest of the REPL to evaluate. It's the "R" in REPL.
return raw[1:] If the line begins with ">", we just strip it and evaluate as valid
Python."""
raw_input_line = input(prompt)
if raw_input_line[0] == '>':
return raw_input_line[1:]
else: else:
cmds = parse_cmds(raw) cmds = parse_cmds(raw_input_line)
cmds.append("Printer()") cmds.append("Printer()")
mangled_input = cmds[0] mangled_input = cmds[0]
for cmd in cmds[1:]: for cmd in cmds[1:]: