@@ -47,16 +47,18 @@ def cli():
47
47
def quickstart ():
48
48
"""Setup warnet"""
49
49
try :
50
+ # Requirements checks
50
51
process = subprocess .Popen (
51
52
["/bin/bash" , str (QUICK_START_PATH )],
52
53
stdout = subprocess .PIPE ,
53
54
stderr = subprocess .STDOUT ,
54
55
universal_newlines = True ,
55
56
env = dict (os .environ , TERM = "xterm-256color" ),
56
57
)
57
- for line in iter (process .stdout .readline , "" ):
58
- click .echo (line , nl = False )
59
- process .stdout .close ()
58
+ if process .stdout :
59
+ for line in iter (process .stdout .readline , "" ):
60
+ click .echo (line , nl = False )
61
+ process .stdout .close ()
60
62
return_code = process .wait ()
61
63
if return_code != 0 :
62
64
click .secho (
@@ -65,67 +67,139 @@ def quickstart():
65
67
click .secho ("Install missing requirements before proceeding" , fg = "yellow" )
66
68
return False
67
69
68
- create_project = click .confirm (
69
- click .style ("\n Do you want to create a new project?" , fg = "blue" , bold = True ),
70
- default = True ,
71
- )
72
- if not create_project :
70
+ # New project setup
71
+ questions = [
72
+ inquirer .Confirm (
73
+ "create_project" ,
74
+ message = click .style ("Do you want to create a new project?" , fg = "blue" , bold = True ),
75
+ default = True ,
76
+ ),
77
+ ]
78
+ answers = inquirer .prompt (questions )
79
+ if answers is None :
80
+ click .secho ("Setup cancelled by user." , fg = "yellow" )
81
+ return False
82
+ if not answers ["create_project" ]:
73
83
click .secho ("\n Setup completed successfully!" , fg = "green" , bold = True )
74
84
return True
75
85
76
- default_path = os .path .abspath (os .getcwd ())
77
- project_path = click .prompt (
78
- click .style ("\n Enter the project directory path" , fg = "blue" , bold = True ),
79
- default = default_path ,
80
- type = click .Path (file_okay = False , dir_okay = True , resolve_path = True ),
81
- )
82
-
83
- custom_network = click .confirm (
84
- click .style ("\n Do you want to create a custom network?" , fg = "blue" , bold = True ),
85
- default = True ,
86
- )
87
- if not custom_network :
88
- create_warnet_project (Path (project_path ))
86
+ # Custom project setup
87
+ questions = [
88
+ inquirer .Path (
89
+ "project_path" ,
90
+ message = click .style ("Enter the project directory path" , fg = "blue" , bold = True ),
91
+ path_type = inquirer .Path .DIRECTORY ,
92
+ exists = False ,
93
+ ),
94
+ inquirer .Confirm (
95
+ "custom_network" ,
96
+ message = click .style (
97
+ "Do you want to create a custom network?" , fg = "blue" , bold = True
98
+ ),
99
+ default = True ,
100
+ ),
101
+ ]
102
+ proj_answers = inquirer .prompt (questions )
103
+ if proj_answers is None :
104
+ click .secho ("Setup cancelled by user." , fg = "yellow" )
105
+ return False
106
+ if not proj_answers ["custom_network" ]:
107
+ create_warnet_project (Path (proj_answers ["project_path" ]))
89
108
click .secho ("\n Setup completed successfully!" , fg = "green" , bold = True )
109
+ click .echo (
110
+ "\n Run the following command to deploy this network using the default demo network:"
111
+ )
112
+ click .echo (f"warcli deploy { proj_answers ['project_path' ]} /networks/6_node_bitcoin" )
90
113
return True
114
+ answers .update (proj_answers )
91
115
92
- network_name = click .prompt (
93
- click .style ("\n Enter the network name" , fg = "blue" , bold = True ),
94
- type = str ,
95
- )
96
-
97
- nodes = click .prompt (
98
- click .style ("\n How many nodes would you like?" , fg = "blue" , bold = True ),
99
- type = int ,
100
- default = 15 ,
101
- )
102
- connections = click .prompt (
103
- click .style (
104
- "\n How many connections would you like each node to have?" , fg = "blue" , bold = True
116
+ # Custom network configuration
117
+ questions = [
118
+ inquirer .Text (
119
+ "network_name" , message = click .style ("Enter your network name" , fg = "blue" , bold = True )
105
120
),
106
- type = int ,
107
- default = 8 ,
108
- )
109
- version = click .prompt (
110
- click .style (
111
- "\n Which version would you like nodes to be by default?" , fg = "blue" , bold = True
121
+ inquirer .List (
122
+ "nodes" ,
123
+ message = click .style ("How many nodes would you like?" , fg = "blue" , bold = True ),
124
+ choices = ["8" , "12" , "20" , "50" , "other" ],
125
+ default = "12" ,
112
126
),
113
- type = click .Choice (SUPPORTED_TAGS , case_sensitive = False ),
114
- default = DEFAULT_TAG ,
115
- )
127
+ inquirer .List (
128
+ "connections" ,
129
+ message = click .style (
130
+ "How many addnode connections would you like each node to have?" ,
131
+ fg = "blue" ,
132
+ bold = True ,
133
+ ),
134
+ choices = ["0" , "1" , "2" , "8" , "12" , "other" ],
135
+ default = "8" ,
136
+ ),
137
+ inquirer .List (
138
+ "version" ,
139
+ message = click .style (
140
+ "Which version would you like nodes to be by default?" , fg = "blue" , bold = True
141
+ ),
142
+ choices = SUPPORTED_TAGS ,
143
+ default = DEFAULT_TAG ,
144
+ ),
145
+ ]
146
+
147
+ net_answers = inquirer .prompt (questions )
148
+ if net_answers is None :
149
+ click .secho ("Setup cancelled by user." , fg = "yellow" )
150
+ return False
151
+
152
+ if net_answers ["nodes" ] == "other" :
153
+ custom_nodes = inquirer .prompt (
154
+ [
155
+ inquirer .Text (
156
+ "nodes" ,
157
+ message = click .style ("Enter the number of nodes" , fg = "blue" , bold = True ),
158
+ validate = lambda _ , x : int (x ) > 0 ,
159
+ )
160
+ ]
161
+ )
162
+ if custom_nodes is None :
163
+ click .secho ("Setup cancelled by user." , fg = "yellow" )
164
+ return False
165
+ net_answers ["nodes" ] = custom_nodes ["nodes" ]
166
+
167
+ if net_answers ["connections" ] == "other" :
168
+ custom_connections = inquirer .prompt (
169
+ [
170
+ inquirer .Text (
171
+ "connections" ,
172
+ message = click .style (
173
+ "Enter the number of connections" , fg = "blue" , bold = True
174
+ ),
175
+ validate = lambda _ , x : int (x ) >= 0 ,
176
+ )
177
+ ]
178
+ )
179
+ if custom_connections is None :
180
+ click .secho ("Setup cancelled by user." , fg = "yellow" )
181
+ return False
182
+ net_answers ["connections" ] = custom_connections ["connections" ]
183
+ answers .update (net_answers )
116
184
117
185
click .secho ("\n Creating project structure..." , fg = "yellow" , bold = True )
118
- create_warnet_project (Path (project_path ))
186
+ create_warnet_project (Path (answers [ " project_path" ] ))
119
187
click .secho ("\n Generating custom network..." , fg = "yellow" , bold = True )
120
- custom_network_path = Path (project_path ) / "networks" / network_name
121
- custom_graph (nodes , connections , version , custom_network_path )
188
+ custom_network_path = Path (answers ["project_path" ]) / "networks" / answers ["network_name" ]
189
+ custom_graph (
190
+ int (answers ["nodes" ]),
191
+ int (answers ["connections" ]),
192
+ answers ["version" ],
193
+ custom_network_path ,
194
+ )
122
195
click .secho ("\n Setup completed successfully!" , fg = "green" , bold = True )
123
196
click .echo ("\n Run the following command to deploy this network:" )
124
197
click .echo (f"warnet deploy { custom_network_path } " )
125
198
except Exception as e :
199
+ click .echo (f"{ e } \n \n " )
126
200
click .secho (f"An error occurred while running the quick start script:\n \n { e } \n \n " , fg = "red" )
127
201
click .secho (
128
- "Please report this to https://github.com/bitcoin-dev-project/warnet/issues" ,
202
+ "Please report the above context to https://github.com/bitcoin-dev-project/warnet/issues" ,
129
203
fg = "yellow" ,
130
204
)
131
205
return False
0 commit comments