1
0
Fork 0
baconscript/bs.py

38 lines
956 B
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Interactive BaconScript shell."""
import logging
import sys
from .bacon import comment, LISTENER, HogNet
from .bacon import load_config as loadBsConfig
# setup logging
LOGGER = logging.getLogger()
LOGGER.setLevel(logging.DEBUG)
LISTENER.osc = HogNet(loadBsConfig('server.cfg'))
# handle user input if run directly
if __name__ == '__main__':
if len(sys.argv) > 1:
# look for macros passed as arguments
logging.debug("found macro at argv[1]")
comment(sys.argv[1])
else:
# 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)