feat(backend): design the cli to look professional
This commit is contained in:
@@ -10,13 +10,11 @@ if TYPE_CHECKING:
|
||||
from backend.cli.base import NimbusFlowCLI
|
||||
|
||||
from backend.models.enums import ScheduleStatus
|
||||
from backend.cli.utils import format_schedule_row
|
||||
from backend.cli.utils import format_schedule_row, create_table_header, create_table_separator, TableColors
|
||||
|
||||
|
||||
def cmd_schedules_list(cli: "NimbusFlowCLI", args) -> None:
|
||||
"""List schedules with optional filters."""
|
||||
print("Listing schedules...")
|
||||
|
||||
schedules = cli.schedule_repo.list_all()
|
||||
|
||||
# Apply filters
|
||||
@@ -28,11 +26,11 @@ def cmd_schedules_list(cli: "NimbusFlowCLI", args) -> None:
|
||||
status_enum = ScheduleStatus.from_raw(args.status.lower())
|
||||
schedules = [s for s in schedules if s.Status == status_enum.value]
|
||||
except ValueError:
|
||||
print(f"❌ Invalid status '{args.status}'. Valid options: pending, accepted, declined")
|
||||
print(f"{TableColors.ERROR}Invalid status '{args.status}'. Valid options: pending, accepted, declined{TableColors.RESET}")
|
||||
return
|
||||
|
||||
if not schedules:
|
||||
print("No schedules found.")
|
||||
print(f"{TableColors.DIM}No schedules found.{TableColors.RESET}")
|
||||
return
|
||||
|
||||
# Get member and service info for display
|
||||
@@ -44,9 +42,10 @@ def cmd_schedules_list(cli: "NimbusFlowCLI", args) -> None:
|
||||
type_name = service_type_map.get(service.ServiceTypeId, "Unknown")
|
||||
service_map[service.ServiceId] = f"{type_name} {service.ServiceDate}"
|
||||
|
||||
# Print header
|
||||
print(f"\n{'ID':<3} | {'Status':<10} | {'Member':<20} | {'Service':<15} | {'Scheduled'}")
|
||||
print("-" * 80)
|
||||
# Print styled header
|
||||
print()
|
||||
print(create_table_header("ID ", "Status ", "Member ", "Service ", "Scheduled"))
|
||||
print(create_table_separator(95))
|
||||
|
||||
# Print schedules
|
||||
for schedule in schedules:
|
||||
@@ -54,14 +53,15 @@ def cmd_schedules_list(cli: "NimbusFlowCLI", args) -> None:
|
||||
service_info = service_map.get(schedule.ServiceId, f"ID:{schedule.ServiceId}")
|
||||
print(format_schedule_row(schedule, member_name, service_info))
|
||||
|
||||
print(f"\nTotal: {len(schedules)} schedules")
|
||||
print()
|
||||
print(f"{TableColors.SUCCESS}Total: {len(schedules)} schedules{TableColors.RESET}")
|
||||
|
||||
|
||||
def cmd_schedules_show(cli: "NimbusFlowCLI", args) -> None:
|
||||
"""Show detailed information about a specific schedule."""
|
||||
schedule = cli.schedule_repo.get_by_id(args.schedule_id)
|
||||
if not schedule:
|
||||
print(f"❌ Schedule with ID {args.schedule_id} not found")
|
||||
print(f"{TableColors.ERROR}Schedule with ID {args.schedule_id} not found{TableColors.RESET}")
|
||||
return
|
||||
|
||||
# Get related information
|
||||
@@ -71,17 +71,39 @@ def cmd_schedules_show(cli: "NimbusFlowCLI", args) -> None:
|
||||
if service:
|
||||
service_type = cli.service_type_repo.get_by_id(service.ServiceTypeId)
|
||||
|
||||
print(f"\n📅 Schedule Details (ID: {schedule.ScheduleId})")
|
||||
print("-" * 50)
|
||||
print(f"Member: {member.FirstName} {member.LastName} (ID: {member.MemberId})" if member else f"Member ID: {schedule.MemberId}")
|
||||
print(f"Service: {service_type.TypeName if service_type else 'Unknown'} on {service.ServiceDate if service else 'Unknown'}")
|
||||
print(f"Status: {schedule.Status.upper()}")
|
||||
print(f"Scheduled At: {schedule.ScheduledAt}")
|
||||
print(f"Accepted At: {schedule.AcceptedAt or 'N/A'}")
|
||||
print(f"Declined At: {schedule.DeclinedAt or 'N/A'}")
|
||||
print(f"Expires At: {schedule.ExpiresAt or 'N/A'}")
|
||||
print(f"\n{TableColors.HEADER}Schedule Details (ID: {schedule.ScheduleId}){TableColors.RESET}")
|
||||
print(f"{TableColors.BORDER}{'─' * 50}{TableColors.RESET}")
|
||||
|
||||
# Member info with color
|
||||
if member:
|
||||
print(f"{TableColors.BOLD}Member:{TableColors.RESET} {TableColors.BOLD}{member.FirstName} {member.LastName}{TableColors.RESET} {TableColors.DIM}(ID: {member.MemberId}){TableColors.RESET}")
|
||||
else:
|
||||
print(f"{TableColors.BOLD}Member:{TableColors.RESET} {TableColors.DIM}Member ID: {schedule.MemberId}{TableColors.RESET}")
|
||||
|
||||
# Service info with color
|
||||
if service_type and service:
|
||||
print(f"{TableColors.BOLD}Service:{TableColors.RESET} {TableColors.YELLOW}{service_type.TypeName}{TableColors.RESET} on {TableColors.BLUE}{service.ServiceDate}{TableColors.RESET}")
|
||||
else:
|
||||
print(f"{TableColors.BOLD}Service:{TableColors.RESET} {TableColors.DIM}Unknown{TableColors.RESET}")
|
||||
|
||||
# Status with appropriate color
|
||||
status_enum = ScheduleStatus.from_raw(schedule.Status)
|
||||
if status_enum == ScheduleStatus.PENDING:
|
||||
status_color = TableColors.WARNING
|
||||
elif status_enum == ScheduleStatus.ACCEPTED:
|
||||
status_color = TableColors.SUCCESS
|
||||
elif status_enum == ScheduleStatus.DECLINED:
|
||||
status_color = TableColors.ERROR
|
||||
else:
|
||||
status_color = TableColors.DIM
|
||||
|
||||
print(f"{TableColors.BOLD}Status:{TableColors.RESET} {status_color}{schedule.Status.upper()}{TableColors.RESET}")
|
||||
print(f"{TableColors.BOLD}Scheduled At:{TableColors.RESET} {schedule.ScheduledAt or f'{TableColors.DIM}N/A{TableColors.RESET}'}")
|
||||
print(f"{TableColors.BOLD}Accepted At:{TableColors.RESET} {schedule.AcceptedAt or f'{TableColors.DIM}N/A{TableColors.RESET}'}")
|
||||
print(f"{TableColors.BOLD}Declined At:{TableColors.RESET} {schedule.DeclinedAt or f'{TableColors.DIM}N/A{TableColors.RESET}'}")
|
||||
print(f"{TableColors.BOLD}Expires At:{TableColors.RESET} {schedule.ExpiresAt or f'{TableColors.DIM}N/A{TableColors.RESET}'}")
|
||||
if schedule.DeclineReason:
|
||||
print(f"Decline Reason: {schedule.DeclineReason}")
|
||||
print(f"{TableColors.BOLD}Decline Reason:{TableColors.RESET} {TableColors.ERROR}{schedule.DeclineReason}{TableColors.RESET}")
|
||||
|
||||
|
||||
def cmd_schedules_accept(cli: "NimbusFlowCLI", args) -> None:
|
||||
|
||||
Reference in New Issue
Block a user