Skip to content

Commit

Permalink
More colorful help menu
Browse files Browse the repository at this point in the history
  • Loading branch information
hg0428 committed Feb 25, 2024
1 parent 815946b commit d89c0fc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Aardvark Interpreter/ArgumentParser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sty import fg
from sty import fg, ef, rs
import sys


Expand Down Expand Up @@ -78,10 +78,10 @@ def print_help(self, message=None, printer=eprint):
printer(message, end="\n\n")

printer(
f"Usage: {self.__name} [command] [...options] [-switches, -keyword args]\n"
f"{ef.bold+fg.red}Usage: {fg.rs+self.__name} [command] [...options] [-flags, -keyword-args]{rs.bold_dim+fg.rs}\n"
)

printer("Commands:")
printer(f"{ef.bold+fg.red}Commands:{rs.bold_dim+fg.rs}")
for command, c, desc in self.__positional:
if len(command) == 0:
continue
Expand All @@ -90,7 +90,7 @@ def print_help(self, message=None, printer=eprint):
f" {' '.join(command).ljust(15, ' ')} {'' if not desc else f' - {desc}'}"
)

printer("\nSwitches and keyword arguments:")
printer(f"\n{ef.bold+fg.red}Flags and keyword arguments:{rs.bold_dim+fg.rs}")
for name in self.__keywords + self.__switches:
desc = self.__arg_descriptions.get(name)
printer(
Expand Down
43 changes: 31 additions & 12 deletions Aardvark Interpreter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@
from Run import *
import sys


if __name__ == "__main__":
import ArgumentParser
from sty import fg, ef, rs

argp = ArgumentParser.ArgumentParser("adk")
argp.switch("version", "Print the current version.")
argp.switch("toks", "Print tokens. If not present, toks are not printed.")
argp.switch("ast", "Print AST. If not present, ast is not printed.")
argp.switch("debug", "Allow $test and $clear commands.")
argp.switch("no-ret", "if set, return values are not printed in live mode.")
argp.switch("no-ret", "if set, return values are not printed in repl mode.")
argp.switch("e", "Use experimental repl.")
argp.switch("safe", "Use safe mode.")
argp.switch("help", "Displays the help menu.")

@argp.command()
def main(ctx):
if ctx.getSwitch("version"):
print("Version info")
elif ctx.getSwitch("help"):
ctx.help()
else:
runLive(
ctx.getSwitch("debug"),
Expand All @@ -30,18 +35,33 @@ def main(ctx):

@argp.command("run [file]", "Compile a file.")
def Run(ctx):
runFile(ctx.positional[1], ctx.getSwitch("toks"), ctx.getSwitch("ast"), safe=ctx.getSwitch("safe"))
if ctx.getSwitch("help"):
print(
f"{ef.bold+fg.red}Usage: {fg.rs}adk run <file> [--safe, -ast, -toks]{rs.bold_dim+fg.rs}\n"
)
else:
runFile(
ctx.positional[1],
ctx.getSwitch("toks"),
ctx.getSwitch("ast"),
safe=ctx.getSwitch("safe"),
)

@argp.command(
"live", "Start an interactable language shell."
) #''Run a live thing (idk what to call it)')
@argp.command("repl", "Start an interactable language shell.")
def live(ctx):
runLive(
ctx.getSwitch("debug"),
ctx.getSwitch("no-ret"),
ctx.getSwitch("toks"),
ctx.getSwitch("ast"),
)
if ctx.getSwitch("help"):
print(
f"{ef.bold+fg.red}Usage: {fg.rs}adk repl [--safe, -ast, -toks, -no-ret, -e, --debug]{rs.bold_dim+fg.rs}\nRun {ef.bold}adk help{rs.bold_dim+fg.rs} for more info.\n"
)
else:
runLive(
ctx.getSwitch("debug"),
ctx.getSwitch("no-ret"),
ctx.getSwitch("toks"),
ctx.getSwitch("ast"),
ctx.getSwitch("e"),
ctx.getSwitch("safe"),
)

@argp.command("help", "Shows help menu.")
def help(ctx):
Expand Down Expand Up @@ -86,5 +106,4 @@ def dotslash(args):
runFile(other[0].removeprefix('./'), 'toks' in opts, 'ast' in opts)
return True
"""

argp.parse(sys.argv[1:])

0 comments on commit d89c0fc

Please sign in to comment.