Skip to content

Commit

Permalink
Use dict for commands
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jul 31, 2024
1 parent c1a21e8 commit 8518658
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions ramalama
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def serve_cli(ramalama_store, args):
os.execlp("llama-server", "llama-server", "-m", symlink_path)


def usage():
def usage(cmd=""):
print("Usage:")
print(f" {os.path.basename(__file__)} COMMAND")
print()
Expand Down Expand Up @@ -323,26 +323,17 @@ def main(args):
conman = select_container_manager()
ramalama_store = get_ramalama_store()

if conman:
conman_args = [conman, "run", "--rm", "-it", "--security-opt=label=disable", f"-v{ramalama_store}:/var/lib/ramalama", f"-v{os.path.expanduser('~')}:{os.path.expanduser('~')}", "-v/tmp:/tmp",
f"-v{__file__}:{__file__}", "quay.io/ramalama/ramalama:latest", __file__] + args
os.execvp(conman, conman_args)

if len(args) < 1:
usage()
funcDict={}
funcDict["pull"] = pull_cli
funcDict["run"] = run_cli
funcDict["list"] = list_cli

cmd = args.pop(0)
if cmd == "pull":
pull_cli(ramalama_store, args)
elif cmd == "run":
run_cli(ramalama_store, args)
elif cmd == "serve":
serve_cli(ramalama_store, args)
elif cmd in ("list", "ls"):
list_cli(ramalama_store)
else:
try:
funcDict[cmd](ramalama_store, args)
except:
print(cmd + " not valid\n")
usage()


if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 8518658

Please sign in to comment.