From d414c8424cee85c5d770f15757f60d3bb1f90e96 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Mon, 18 Nov 2019 13:22:31 -0500 Subject: [PATCH] move shell interpreter to own file --- bs.py | 31 +++++++++++++++++++++++++++++++ setup.py | 0 2 files changed, 31 insertions(+) create mode 100755 bs.py mode change 100644 => 100755 setup.py diff --git a/bs.py b/bs.py new file mode 100755 index 0000000..f51e406 --- /dev/null +++ b/bs.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Interactive BaconScript shell. +""" + +import sys +from bacon.script import comment + +# handle user input if run directly +if __name__ == '__main__': + if len(sys.argv) > 1: + # look for macros passed as arguments + logger.debug("found macro at argv[1]") + comment(sys.argv[1]) + else: + # for input history and line editing + import readline + # be an interactive shell + while True: + # get user input + try: + text = input("comment# ") + except (KeyboardInterrupt, EOFError): + text = 'exit' + print(text) + # catch exit keyword + if text.lower() == 'exit': + break + # exec user input + comment(text) diff --git a/setup.py b/setup.py old mode 100644 new mode 100755