Skip to content

Commit

Permalink
fix(__main__.py): fix logger levels
Browse files Browse the repository at this point in the history
  • Loading branch information
aadhithya committed May 16, 2022
1 parent 70a49d3 commit a0000b3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions rajinipp/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pdb
import sys

from loguru import logger
from typer import Typer

from . import __version__, __version_str__
from .runner import RppRunner

app = Typer()
runner = RppRunner()


@app.command()
Expand All @@ -18,8 +18,13 @@ def version():
@app.command()
def tokenize(file_path: str):
"""prints the tokens from the program."""
logger.remove()
logger.add(sys.stderr, level="ERROR")

with open(file_path, "r") as f:
code_str = f.read()

runner = RppRunner()
tokens = runner.tokenize(code=code_str)
for token in tokens:
print(token)
Expand All @@ -28,15 +33,21 @@ def tokenize(file_path: str):
@app.command()
def run(file_path: str, debug: bool = False):
"""executes a rajini++ program."""
level = "DEBUG" if debug else "INFO"
level = "DEBUG" if debug else "ERROR"
logger.remove()
logger.add(sys.stderr, level=level)

with open(file_path, "r") as f:
code_str = f.read()

runner = RppRunner()
runner.exec(code=code_str, log_level=level)


@app.command()
def shell():
print(f"rajini++ v{'0.2.0'}")
runner = RppRunner()
print(f"rajini++ v{__version__}")
while True:
code_line = input("rajinipp>> ")
output = runner.eval(code_line)
Expand Down

0 comments on commit a0000b3

Please sign in to comment.