-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_cli.py
More file actions
76 lines (65 loc) · 3.89 KB
/
interactive_cli.py
File metadata and controls
76 lines (65 loc) · 3.89 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
import subprocess
import sys
import os
from colorama import init, Fore, Style
# Initialize colorama
init(autoreset=True)
def resource_path(relative_path):
"""Get the absolute path to a resource, works for PyInstaller"""
if getattr(sys, '_MEIPASS', False): # If running in a PyInstaller bundle
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
def print_ascii_banner():
banner = """
{}
::
%%
%%
#*:*##%#+. -*###%#= -*%###+:%% .=#####+: .+#%%%#+: =*%%%%#+. .=*%%%%#=. *#+=#%%%#=. :+#%%%#+:
%%#. -%# #%- :#%. +%+ -%%% :%# *%- .%%%:.-**= .%%%#)%%%. -%%% %%%: #%%%*==*%%%: =%%# *%%=
%% #% *%- .%# :%+ .%% %%=::::::%% #%%+-:. *%%: .%%%: .%%# #%%. :%%% :%%%=====#%%
%# *% %%. #% =%- %% .%%========= -+*#%%%+ #%% .%%# *%% #%* #%%.-%%.
%# *% =%+ -%+ .%# =%% *%- -. .-+: +%%- =%%+. =+-. #%%+. .=%%* #%%= .+%%* %%%: ==.
%# *% :##=--=#%= :#%+--=#*%% =%*=--+%#: .*%%%##%%* =#%%%%%%%+ +%%%%%%%%= #%%#%%%%%%= .*%%%#%%%#:
-- :- :-===: .===-. -- :===-. .-===-. :-===- :====: #%# :===- -===-.
#%#
#%#
Nodescope: an XML Editor and Visualizer
{}""".format(Fore.CYAN, Style.RESET_ALL)
print(banner)
def interactive_loop():
print_ascii_banner()
try:
from src.cli.cli_handler import main as cli_main # Import the CLI handler's main function
except ImportError as e:
print(f"{Fore.RED}Error importing CLI handler: {e}{Style.RESET_ALL}")
sys.exit(1)
while True:
try:
command = input(f"{Fore.GREEN}>> {Style.RESET_ALL}").strip()
if command.lower() in ["exit", "quit"]:
print(f"{Fore.LIGHTRED_EX}Exiting CLI mode. Goodbye!{Style.RESET_ALL}")
sys.exit(0)
elif not command:
continue # Skip empty commands
# Split the command into arguments
args = command.split()
# Backup original sys.argv
original_argv = sys.argv.copy()
# Set sys.argv to mimic command-line arguments
sys.argv = [sys.executable, *args]
try:
cli_main() # Call the CLI handler's main function
except SystemExit:
# argparse may call sys.exit(), which raises SystemExit
pass
finally:
# Restore original sys.argv
sys.argv = original_argv
except KeyboardInterrupt:
print(f"\n{Fore.LIGHTRED_EX}Exiting CLI mode. Goodbye!{Style.RESET_ALL}")
sys.exit(0)
except Exception as e:
print(f"{Fore.RED}An unexpected error occurred: {e}{Style.RESET_ALL}")
if __name__ == "__main__":
interactive_loop()