mirror of
https://github.com/danielmiessler/fabric
synced 2024-11-08 07:11:06 +00:00
added ability to list sessions and gives the first line
This commit is contained in:
parent
b5ee3d38a3
commit
989cb9b8d4
@ -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:
|
||||
|
@ -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\"")
|
||||
|
Loading…
Reference in New Issue
Block a user