99from paths_cli .parsing .core import custom_eval
1010from paths_cli .wizard .joke import name_joke
1111
12+ DISPLAY_NAME = {
13+ 'engines' : "engine" ,
14+ 'cvs' : "CV" ,
15+ 'states' : "state" ,
16+ 'tps_network' : "network" ,
17+ }
18+
1219WIZARD_PAGES = {
1320 "engines" : (engines , "engine" ),
1421 "cvs" : (cvs , "cv" ),
@@ -44,6 +51,9 @@ def __init__(self, requirements):
4451 self .console = Console ()
4552 self .default = {}
4653
54+ def debug (content ):
55+ self .console .print (content )
56+
4757 def _speak (self , content , preface ):
4858 # we do custom wrapping here
4959 width = self .console .width - len (preface )
@@ -109,7 +119,7 @@ def ask_custom_eval(self, question, options=None, default=None,
109119 return result
110120
111121 def obj_selector (self , store_name , text_name , create_func ):
112- opts = {name : lambda wiz : obj
122+ opts = {name : lambda wiz , o = obj : o
113123 for name , obj in getattr (self , store_name ).items ()}
114124 create_new = f"Create a new { text_name } "
115125 opts [create_new ] = create_func
@@ -123,16 +133,15 @@ def obj_selector(self, store_name, text_name, create_func):
123133 def exception (self , msg , exception ):
124134 self .bad_input (msg + "\n Here's the error I got:\n " + str (exception ))
125135
126- def _req_allows_another (self , req ):
127- store , num , direction = req
136+ def _req_do_another (self , req ):
137+ store , min_ , max_ = req
128138 if store is None :
129- return True
139+ return ( True , False )
130140
131141 count = len (getattr (self , store ))
132- result = {'=' : count < num ,
133- '+' : True ,
134- '-' : count < num }[direction ]
135- return result
142+ allows = count < max_
143+ requires = count < min_
144+ return requires , allows
136145
137146 def name (self , obj , obj_type , store_name , default = None ):
138147 self .say (f"Now let's name your { obj_type } ." )
@@ -187,22 +196,44 @@ def save_to_file(self):
187196 def _do_storage (self , storage ):
188197 pass
189198
199+ def _ask_do_another (self , obj_type ):
200+ do_another = None
201+ while do_another is None :
202+ do_another_char = self .ask (
203+ f"Would you like to make another { obj_type } ?" ,
204+ options = ["[Y]es" , "[N]o" ]
205+ )
206+ try :
207+ do_another = yes_no (do_another_char )
208+ except KeyError :
209+ self .bad_input ("Sorry, I didn't understand that." )
210+ return do_another
211+
190212 def run_wizard (self ):
191213 for page , req in self .requirements .items ():
192214 store_name , _ , _ = req
193- while self ._req_allows_another (req ):
215+ do_another = True
216+ while do_another :
194217 func , obj_type = WIZARD_PAGES [page ]
195218 obj = func (self )
196219 self .register (obj , obj_type , store_name )
220+ requires_another , allows_another = self ._req_do_another (req )
221+ if requires_another :
222+ do_another = True
223+ elif not requires_another and allows_another :
224+ do_another = self ._ask_do_another (obj_type )
225+ else :
226+ do_another = False
227+
197228
198229
199230TPS_WIZARD = Wizard ({
200231 # WIZARD_PAGE_NAME: (store_name, num, exact/at least/at most)
201- 'engines' : ('engines' , 1 , '=' ),
202- 'cvs' : ('cvs' , 1 , '+' ),
203- 'states' : ('states' , 2 , '+' ),
204- 'tps_network' : ('metworks' , 1 , '=' ),
205- 'tps_scheme' : ('schemes' , 1 , '=' ),
232+ 'engines' : ('engines' , 1 , 1 ),
233+ 'cvs' : ('cvs' , 1 , float ( 'inf' ) ),
234+ 'states' : ('states' , 2 , float ( 'inf' ) ),
235+ 'tps_network' : ('metworks' , 1 , 1 ),
236+ 'tps_scheme' : ('schemes' , 1 , 1 ),
206237 'tps_finalize' : (None , None , None ),
207238})
208239
@@ -222,3 +253,6 @@ def run_wizard(self):
222253 'mstis_network' : (1 , '=' ),
223254 'mstis_scheme' : (1 , '=' ),
224255})
256+
257+ if __name__ == "__main__" :
258+ TPS_WIZARD .run_wizard ()
0 commit comments