added while loop for top level config menu, updated delete question to standard we are using

This commit is contained in:
2022-09-06 20:39:56 -04:00
parent 7d9e4fa428
commit 5958bfdd55

View File

@@ -113,44 +113,46 @@ if __name__ == "__main__":
sys.exit(0) sys.exit(0)
else: else:
print("This value must be one of the following characters: n, q.") print("This value must be one of the following characters: n, q.")
config = configparser.ConfigParser()
config.read(secrets_ini_file)
accounts = config.sections()
print("Current Bitwarden accounts:")
for account in accounts:
print(account)
print(" ")
print("e) Edit account")
print("n) New account")
print("d) Delete account")
print("q) Quit config")
while True: while True:
user_input = input("e/n/d/q> ") config = configparser.ConfigParser()
if user_input.casefold() == "e": config.read(secrets_ini_file)
print("") accounts = config.sections()
elif user_input.casefold() == "n": print("Current Bitwarden accounts:")
account_details = ask_for_account_details() print(" ")
config.add_section(account_details["account_email_address"]) for account in accounts:
for key in account_details.keys(): print(account)
if not key == "account_email_address": print(" ")
config.set(account_details["account_email_address"], key, account_details[key]) print("e) Edit account")
with open(secrets_ini_file, "w") as configfile: print("n) New account")
config.write(configfile) print("d) Delete account")
break print("q) Quit config")
elif user_input.casefold() == "d": while True:
account_section_to_delete = select_account(accounts, "delete") user_input = input("e/n/d/q> ")
confirmation = input("Are you sure you wish to delete {} account?".format(account_section_to_delete)) if user_input.casefold() == "e":
if not confirmation.casefold() in ["y","yes"]: account_section_to_edit = select_account(accounts)
elif user_input.casefold() == "n":
account_details = ask_for_account_details()
config.add_section(account_details["account_email_address"])
for key in account_details.keys():
if not key == "account_email_address":
config.set(account_details["account_email_address"], key, account_details[key])
with open(secrets_ini_file, "w") as configfile:
config.write(configfile)
break break
config.remove_section(account_section_to_delete) elif user_input.casefold() == "d":
with open(secrets_ini_file, "w") as configfile: account_section_to_delete = select_account(accounts, "delete")
config.write(configfile) print("Are you sure you wish to delete {} account? ".format(account_section_to_delete))
break confirmation = input("y/n> ")
elif user_input.casefold() == "q": if not confirmation.casefold() in ["y","yes"]:
sys.exit(0) break
else: config.remove_section(account_section_to_delete)
print("This value must be one of the following characters: e, n, d, q.") with open(secrets_ini_file, "w") as configfile:
config.write(configfile)
break
elif user_input.casefold() == "q":
sys.exit(0)
else:
print("This value must be one of the following characters: e, n, d, q.")
sys.exit(0) sys.exit(0)