diff --git a/installer/client/cli/fabric.py b/installer/client/cli/fabric.py index fe81397..f9596e2 100755 --- a/installer/client/cli/fabric.py +++ b/installer/client/cli/fabric.py @@ -30,8 +30,11 @@ def main(): ) parser.add_argument('--session', '-S', help="Continue your previous conversation. Default is your previous conversation", nargs="?", const="default") - parser.add_argument('--clearsession', help="deletes indicated session. Use 'all' to delete all dessions") + parser.add_argument( + '--clearsession', help="deletes indicated session. Use 'all' to delete all dessions") parser.add_argument('--sessionlog', help="View the log of a session") + parser.add_argument( + '--listsessions', help="List all sessions", action="store_true") parser.add_argument( "--gui", help="Use the GUI (Node and npm need to be installed)", action="store_true") parser.add_argument( @@ -139,6 +142,11 @@ def main(): session = Session() print(session.session_log(args.sessionlog)) sys.exit() + if args.listsessions: + from .helper import Session + session = Session() + session.list_sessions() + sys.exit() standalone = Standalone(args, args.pattern) if args.list: try: diff --git a/installer/client/cli/helper.py b/installer/client/cli/helper.py index da4815d..afde5ec 100644 --- a/installer/client/cli/helper.py +++ b/installer/client/cli/helper.py @@ -43,15 +43,29 @@ class Session: return None with open(file, "r") as f: return f.read() + def clear_session(self, session): if session == "all": for file in os.listdir(self.sessions_folder): os.remove(os.path.join(self.sessions_folder, file)) else: os.remove(os.path.join(self.sessions_folder, session)) + def session_log(self, session): file = os.path.join(self.sessions_folder, session) if not os.path.exists(file): return None with open(file, "r") as f: return f.read() + + def list_sessions(self): + sessionlist = os.listdir(self.sessions_folder) + most_recent = self.find_most_recent_file().split("/")[-1] + for session in sessionlist: + with open(os.path.join(self.sessions_folder, session), "r") as f: + firstline = f.readline().strip() + secondline = f.readline().strip() + if session == most_recent: + print(f"{session} **default** \"{firstline}\n{secondline}\n\"") + else: + print(f"{session} \"{firstline}\n{secondline}\n\"")