From d89c0fcf90b49005e32f0b463b2db531365f9873 Mon Sep 17 00:00:00 2001 From: Hudson Gouge Date: Sun, 25 Feb 2024 16:28:00 -0500 Subject: [PATCH] More colorful help menu --- Aardvark Interpreter/ArgumentParser.py | 8 ++--- Aardvark Interpreter/main.py | 43 +++++++++++++++++++------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Aardvark Interpreter/ArgumentParser.py b/Aardvark Interpreter/ArgumentParser.py index 48dfdf04..545469e5 100644 --- a/Aardvark Interpreter/ArgumentParser.py +++ b/Aardvark Interpreter/ArgumentParser.py @@ -1,4 +1,4 @@ -from sty import fg +from sty import fg, ef, rs import sys @@ -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 @@ -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( diff --git a/Aardvark Interpreter/main.py b/Aardvark Interpreter/main.py index 9ca9201c..4f79d0ec 100755 --- a/Aardvark Interpreter/main.py +++ b/Aardvark Interpreter/main.py @@ -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"), @@ -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 [--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): @@ -86,5 +106,4 @@ def dotslash(args): runFile(other[0].removeprefix('./'), 'toks' in opts, 'ast' in opts) return True """ - argp.parse(sys.argv[1:])