added additional functions
This commit is contained in:
parent
1e55abf811
commit
67a5534246
8 changed files with 654 additions and 107 deletions
32
cli.py
32
cli.py
|
@ -1,31 +1,32 @@
|
|||
# ssh_manager/cli.py
|
||||
|
||||
import os
|
||||
import glob
|
||||
import asyncio
|
||||
from .utils import print_info, print_error, print_warning, Colors
|
||||
from .utils import print_info, print_error, print_warning, Colors, safe_input
|
||||
from .config import SSH_DIR, CONF_DIR, SOCKET_DIR, MAIN_CONFIG, DEFAULT_CONFIG_CONTENT
|
||||
from .add_host import add_host
|
||||
from .edit_host import edit_host
|
||||
from .list_hosts import list_hosts
|
||||
from .regen_key import regenerate_key
|
||||
from .remove_host import remove_host
|
||||
|
||||
def ensure_ssh_setup():
|
||||
# Make ~/.ssh if missing
|
||||
"""
|
||||
Creates ~/.ssh, ~/.ssh/conf, and ~/.ssh/s if missing,
|
||||
and writes a default ~/.ssh/config if it doesn't exist.
|
||||
"""
|
||||
if not os.path.isdir(SSH_DIR):
|
||||
os.makedirs(SSH_DIR, mode=0o700, exist_ok=True)
|
||||
print_info(f"Created directory: {SSH_DIR}")
|
||||
|
||||
# Make ~/.ssh/conf if missing
|
||||
if not os.path.isdir(CONF_DIR):
|
||||
os.makedirs(CONF_DIR, mode=0o700, exist_ok=True)
|
||||
print_info(f"Created directory: {CONF_DIR}")
|
||||
|
||||
# Make ~/.ssh/s if missing
|
||||
if not os.path.isdir(SOCKET_DIR):
|
||||
os.makedirs(SOCKET_DIR, mode=0o700, exist_ok=True)
|
||||
print_info(f"Created directory: {SOCKET_DIR}")
|
||||
|
||||
# Create ~/.ssh/config if not present
|
||||
if not os.path.isfile(MAIN_CONFIG):
|
||||
with open(MAIN_CONFIG, "w") as f:
|
||||
f.write(DEFAULT_CONFIG_CONTENT)
|
||||
|
@ -34,14 +35,23 @@ def ensure_ssh_setup():
|
|||
def main():
|
||||
ensure_ssh_setup()
|
||||
|
||||
# Display the server list on first load
|
||||
asyncio.run(list_hosts(CONF_DIR))
|
||||
|
||||
while True:
|
||||
print("\n" + f"{Colors.CYAN}{Colors.BOLD}SSH Config Manager Menu{Colors.RESET}")
|
||||
print("1. List Hosts")
|
||||
print("2. Add a Host")
|
||||
print("3. Edit a Host")
|
||||
print("4. Exit")
|
||||
print("4. Regenerate Key")
|
||||
print("5. Remove Host")
|
||||
print("6. Exit")
|
||||
|
||||
choice = input("Select an option (1-4): ").strip()
|
||||
choice = safe_input("Select an option (1-6): ")
|
||||
if choice is None:
|
||||
continue # User pressed Ctrl+C => safe_input returns None => re-show menu
|
||||
|
||||
choice = choice.strip()
|
||||
if choice == '1':
|
||||
asyncio.run(list_hosts(CONF_DIR))
|
||||
elif choice == '2':
|
||||
|
@ -49,9 +59,13 @@ def main():
|
|||
elif choice == '3':
|
||||
edit_host(CONF_DIR)
|
||||
elif choice == '4':
|
||||
asyncio.run(regenerate_key(CONF_DIR))
|
||||
elif choice == '5':
|
||||
asyncio.run(remove_host(CONF_DIR))
|
||||
elif choice == '6':
|
||||
print_info("Exiting...")
|
||||
break
|
||||
else:
|
||||
print_error("Invalid choice. Please select 1, 2, 3, or 4.")
|
||||
print_error("Invalid choice. Please select 1 through 6.")
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue