converted into multifile for ease
This commit is contained in:
parent
bfdcf11212
commit
2a7cb7dcb7
9 changed files with 148 additions and 176 deletions
57
cli.py
Normal file
57
cli.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
# ssh_manager/cli.py
|
||||
|
||||
import os
|
||||
import glob
|
||||
import asyncio
|
||||
from .utils import print_info, print_error, print_warning, Colors
|
||||
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
|
||||
|
||||
def ensure_ssh_setup():
|
||||
# Make ~/.ssh if missing
|
||||
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)
|
||||
print_info(f"Created default SSH config at: {MAIN_CONFIG}")
|
||||
|
||||
def main():
|
||||
ensure_ssh_setup()
|
||||
|
||||
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")
|
||||
|
||||
choice = input("Select an option (1-4): ").strip()
|
||||
if choice == '1':
|
||||
asyncio.run(list_hosts(CONF_DIR))
|
||||
elif choice == '2':
|
||||
add_host(CONF_DIR)
|
||||
elif choice == '3':
|
||||
edit_host(CONF_DIR)
|
||||
elif choice == '4':
|
||||
print_info("Exiting...")
|
||||
break
|
||||
else:
|
||||
print_error("Invalid choice. Please select 1, 2, 3, or 4.")
|
||||
|
||||
return 0
|
Loading…
Add table
Add a link
Reference in a new issue