7
7
8
8
import click
9
9
import yaml
10
- from rich import print as richprint
11
10
12
11
from .admin import admin
13
12
from .bitcoin import bitcoin
17
16
from .image import image
18
17
from .network import copy_network_defaults , copy_scenario_defaults
19
18
from .status import status as status_command
20
- from .util import SUPPORTED_TAGS
19
+ from .util import DEFAULT_TAG , SUPPORTED_TAGS
21
20
22
21
QUICK_START_PATH = files ("resources.scripts" ).joinpath ("quick_start.sh" )
23
22
@@ -54,62 +53,92 @@ def quickstart():
54
53
process .stdout .close ()
55
54
return_code = process .wait ()
56
55
if return_code != 0 :
57
- click .echo (f"Quick start script failed with return code { return_code } " )
58
- click .echo ("Install missing requirements before proceeding" )
56
+ click .secho (
57
+ f"Quick start script failed with return code { return_code } " , fg = "red" , bold = True
58
+ )
59
+ click .secho ("Install missing requirements before proceeding" , fg = "yellow" )
59
60
return False
60
61
61
- create_project = click .confirm ("Do you want to create a new project?" , default = True )
62
+ create_project = click .confirm (
63
+ click .style ("\n Do you want to create a new project?" , fg = "blue" , bold = True ),
64
+ default = True ,
65
+ )
62
66
if not create_project :
63
- click .echo ( "Setup completed successfully!" )
67
+ click .secho ( " \n Setup completed successfully!", fg = "green" , bold = True )
64
68
return True
65
69
66
70
default_path = os .path .abspath (os .getcwd ())
67
71
project_path = click .prompt (
68
- "Enter the project directory path" ,
72
+ click . style ( " \n Enter the project directory path", fg = "blue" , bold = True ) ,
69
73
default = default_path ,
70
74
type = click .Path (file_okay = False , dir_okay = True , resolve_path = True ),
71
75
)
72
76
73
- custom_network = click .confirm ("Do you want to create a custom network?" , default = True )
77
+ custom_network = click .confirm (
78
+ click .style ("\n Do you want to create a custom network?" , fg = "blue" , bold = True ),
79
+ default = True ,
80
+ )
74
81
if not custom_network :
75
82
create_warnet_project (Path (project_path ))
76
- click .echo ( "Setup completed successfully!" )
83
+ click .secho ( " \n Setup completed successfully!", fg = "green" , bold = True )
77
84
return True
78
85
79
86
network_name = click .prompt (
80
- "Enter the network name" ,
87
+ click . style ( " \n Enter the network name", fg = "blue" , bold = True ) ,
81
88
type = str ,
82
89
)
83
- nodes = click .prompt ("How many nodes would you like?" , type = int )
84
- connections = click .prompt ("How many connects would you like each node to have?" , type = int )
90
+
91
+ nodes = click .prompt (
92
+ click .style ("\n How many nodes would you like?" , fg = "blue" , bold = True ),
93
+ type = int ,
94
+ default = 15 ,
95
+ )
96
+ connections = click .prompt (
97
+ click .style (
98
+ "\n How many connections would you like each node to have?" , fg = "blue" , bold = True
99
+ ),
100
+ type = int ,
101
+ default = 8 ,
102
+ )
85
103
version = click .prompt (
86
- "Which version would you like nodes to have by default?" ,
104
+ click .style (
105
+ "\n Which version would you like nodes to be by default?" , fg = "blue" , bold = True
106
+ ),
87
107
type = click .Choice (SUPPORTED_TAGS , case_sensitive = False ),
108
+ default = DEFAULT_TAG ,
88
109
)
89
110
111
+ click .secho ("\n Creating project structure..." , fg = "yellow" , bold = True )
90
112
create_warnet_project (Path (project_path ))
91
- custom_graph (nodes , connections , version , Path (project_path ) / "networks" / network_name )
92
-
113
+ click .secho ("\n Generating custom network..." , fg = "yellow" , bold = True )
114
+ custom_network_path = Path (project_path ) / "networks" / network_name
115
+ custom_graph (nodes , connections , version , custom_network_path )
116
+ click .secho ("\n Setup completed successfully!" , fg = "green" , bold = True )
117
+ click .echo ("\n Run the following command to deploy this network:" )
118
+ click .echo (f"warcli deploy { custom_network_path } " )
93
119
except Exception as e :
94
- print (f"An error occurred while running the quick start script:\n \n { e } \n \n " )
95
- print ("Please report this to https://github.com/bitcoin-dev-project/warnet/issues" )
120
+ click .secho (f"An error occurred while running the quick start script:\n \n { e } \n \n " , fg = "red" )
121
+ click .secho (
122
+ "Please report this to https://github.com/bitcoin-dev-project/warnet/issues" ,
123
+ fg = "yellow" ,
124
+ )
96
125
return False
97
126
98
127
99
128
def create_warnet_project (directory : Path , check_empty : bool = False ):
100
129
"""Common function to create a warnet project"""
101
130
if check_empty and any (directory .iterdir ()):
102
- richprint ( "[yellow] Warning: Directory is not empty[/ yellow] " )
131
+ click . secho ( " Warning: Directory is not empty" , fg = " yellow" )
103
132
if not click .confirm ("Do you want to continue?" , default = True ):
104
133
return
105
134
106
135
try :
107
136
copy_network_defaults (directory )
108
137
copy_scenario_defaults (directory )
109
- richprint (f"[green] Copied network example files to { directory / 'networks' } [/green] " )
110
- richprint (f"[green] Created warnet project structure in { directory } [/green] " )
138
+ click . echo (f"Copied network example files to { directory } /networks " )
139
+ click . echo (f"Created warnet project structure in { directory } " )
111
140
except Exception as e :
112
- richprint (f"[red] Error creating project: { e } [/ red] " )
141
+ click . secho (f"Error creating project: { e } " , fg = " red" )
113
142
raise e
114
143
115
144
@@ -120,7 +149,7 @@ def create_warnet_project(directory: Path, check_empty: bool = False):
120
149
def create (directory : Path ):
121
150
"""Create a new warnet project in the specified directory"""
122
151
if directory .exists ():
123
- richprint (f"[red] Error: Directory { directory } already exists[/ red] " )
152
+ click . secho (f"Error: Directory { directory } already exists" , fg = " red" )
124
153
return
125
154
create_warnet_project (directory )
126
155
@@ -155,17 +184,17 @@ def auth(kube_config: str) -> None:
155
184
flatten_cmd , shell = True , check = True , capture_output = True , text = True
156
185
)
157
186
except subprocess .CalledProcessError as e :
158
- print ("Error occurred while executing kubectl config view --flatten:" )
159
- print (e .stderr )
187
+ click . secho ("Error occurred while executing kubectl config view --flatten:" , fg = "red " )
188
+ click . secho (e .stderr , fg = "red" )
160
189
sys .exit (1 )
161
190
162
191
if result_flatten .returncode == 0 :
163
192
with open (current_kubeconfig , "w" ) as file :
164
193
file .write (result_flatten .stdout )
165
- print (f"Authorization file written to: { current_kubeconfig } " )
194
+ click . secho (f"Authorization file written to: { current_kubeconfig } " , fg = "green " )
166
195
else :
167
- print ("Could not create authorization file" )
168
- print (result_flatten .stderr )
196
+ click . secho ("Could not create authorization file" , fg = "red " )
197
+ click . secho (result_flatten .stderr , fg = "red" )
169
198
sys .exit (result_flatten .returncode )
170
199
171
200
try :
@@ -174,12 +203,12 @@ def auth(kube_config: str) -> None:
174
203
update_cmd , shell = True , check = True , capture_output = True , text = True
175
204
)
176
205
if result_update .returncode != 0 :
177
- print ("Could not update authorization file" )
178
- print (result_flatten .stderr )
206
+ click . secho ("Could not update authorization file" , fg = "red " )
207
+ click . secho (result_flatten .stderr , fg = "red" )
179
208
sys .exit (result_flatten .returncode )
180
209
except subprocess .CalledProcessError as e :
181
- print ("Error occurred while executing kubectl config view --flatten:" )
182
- print (e .stderr )
210
+ click . secho ("Error occurred while executing kubectl config view --flatten:" , fg = "red " )
211
+ click . secho (e .stderr , fg = "red" )
183
212
sys .exit (1 )
184
213
185
214
with open (current_kubeconfig ) as file :
@@ -191,7 +220,9 @@ def auth(kube_config: str) -> None:
191
220
192
221
with open (current_kubeconfig ) as file :
193
222
contents = yaml .safe_load (file )
194
- print (f"\n Warcli's current context is now set to: { contents ['current-context' ]} " )
223
+ click .secho (
224
+ f"\n Warcli's current context is now set to: { contents ['current-context' ]} " , fg = "green"
225
+ )
195
226
196
227
197
228
if __name__ == "__main__" :
0 commit comments