-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteamdynamix_cli.py
More file actions
150 lines (128 loc) · 4.59 KB
/
teamdynamix_cli.py
File metadata and controls
150 lines (128 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env python3
"""
TeamDynamix API Command Line Interface
An interactive CLI for working with the TeamDynamix API
"""
import os
import sys
from dotenv import load_dotenv
from colorama import Fore, Back, Style, init
# Initialize colorama
init(autoreset=True)
# Import modules from the package
from teamdynamix.auth.client import AuthClient
from teamdynamix.people.client import PeopleClient
from teamdynamix.tickets.client import TicketsClient
from teamdynamix.people.commands import (
search_people_command,
get_person_details_command,
get_person_by_username_command,
get_uid_by_username_command,
)
from teamdynamix.tickets.commands import (
search_tickets_command,
get_ticket_command,
create_ticket_command,
create_ticket_comment_command,
select_application_command,
)
from teamdynamix.utils.cli import (
clear_screen,
display_title,
divider,
box,
display_pixelated_tdx,
display_bordered_ascii,
)
def main_menu(auth):
"""Display the main menu and handle user selection"""
# Initialize clients
people_client = PeopleClient(auth)
tickets_client = TicketsClient(auth)
while True:
clear_screen()
display_bordered_ascii()
# Status information in a box
user_info = auth.get_current_user()
user_name = "Unknown"
if user_info:
user_name = user_info.get("FullName", "Unknown")
status_info = (
f"Environment: {auth.environment.title()}\n"
f"API URL: {auth.base_url}\n"
f"User: {user_name}"
)
print(
f"{Fore.CYAN}{box(status_info, width=60, style='rounded')}{Style.RESET_ALL}"
)
print()
# Menu options
print(f"{Fore.MAGENTA}{Style.BRIGHT}PEOPLE OPERATIONS:{Style.RESET_ALL}")
print(f"{Fore.WHITE}1. {Fore.LIGHTBLUE_EX}Search for People{Style.RESET_ALL}")
print(
f"{Fore.WHITE}2. {Fore.LIGHTBLUE_EX}Get Person Details by UID{Style.RESET_ALL}"
)
print(
f"{Fore.WHITE}3. {Fore.LIGHTBLUE_EX}Get Person Details by Username{Style.RESET_ALL}"
)
print(f"{Fore.WHITE}4. {Fore.LIGHTBLUE_EX}Get UID by Username{Style.RESET_ALL}")
print()
print(f"{Fore.MAGENTA}{Style.BRIGHT}TICKET OPERATIONS:{Style.RESET_ALL}")
print(f"{Fore.WHITE}5. {Fore.LIGHTBLUE_EX}Ticket Operations{Style.RESET_ALL}")
print()
print(f"{Fore.MAGENTA}{Style.BRIGHT}SYSTEM:{Style.RESET_ALL}")
print(f"{Fore.WHITE}S. {Fore.LIGHTBLUE_EX}Switch Environment{Style.RESET_ALL}")
print(f"{Fore.WHITE}X. {Fore.LIGHTBLUE_EX}Exit{Style.RESET_ALL}")
print()
choice = (
input(f"{Fore.GREEN}Select an option: {Style.RESET_ALL}").strip().lower()
)
# People operations
if choice == "1":
search_people_command(people_client)
elif choice == "2":
get_person_details_command(people_client)
elif choice == "3":
get_person_by_username_command(people_client)
elif choice == "4":
get_uid_by_username_command(people_client)
# Ticket operations
elif choice == "5":
select_application_command(tickets_client)
# System operations
elif choice == "s":
return True # Signal to switch environment
elif choice == "x":
return False # Signal to exit
else:
print(f"{Fore.RED}Invalid selection. Please try again.{Style.RESET_ALL}")
input(f"\n{Fore.YELLOW}Press Enter to continue...{Style.RESET_ALL}")
def main():
"""Main entry point for the CLI"""
# Load environment variables
load_dotenv()
# Welcome message
clear_screen()
display_bordered_ascii()
welcome_text = "Welcome to TDX Python CLI. This tool allows you to interact with the TeamDynamix API."
print(f"{Fore.CYAN}{box(welcome_text, width=60, style='double')}{Style.RESET_ALL}")
print()
switch_env = True
while switch_env:
# Select environment
environment = AuthClient.select_environment()
# Authenticate
auth = AuthClient.authenticate(environment)
if not auth:
input(f"\n{Fore.YELLOW}Press Enter to try again...{Style.RESET_ALL}")
continue
# Show main menu
switch_env = main_menu(auth)
# Goodbye message
clear_screen()
display_bordered_ascii()
goodbye_text = "Thank you for using TDX Python CLI. Goodbye!"
print(f"{Fore.CYAN}{box(goodbye_text, width=60, style='rounded')}{Style.RESET_ALL}")
return 0
if __name__ == "__main__":
sys.exit(main())