33import datetime
44
55from . import flow , lib
6- from .setup import check_setup_status , CheckSetupStatusOptions , apply_setup_changes
6+ from .setup import sync_setup , drop_setup , flow_names_with_setup , apply_setup_changes
77
88@click .group ()
99def cli ():
@@ -12,12 +12,42 @@ def cli():
1212 """
1313
1414@cli .command ()
15- def ls ():
15+ @click .option (
16+ "-a" , "--all" , "show_all" , is_flag = True , show_default = True , default = False ,
17+ help = "Also show all flows with persisted setup, even if not defined in the current process." )
18+ def ls (show_all : bool ):
1619 """
17- List all available flows.
20+ List all flows.
1821 """
19- for name in flow .flow_names ():
20- click .echo (name )
22+ current_flow_names = [fl .name for fl in flow .flows ()]
23+ persisted_flow_names = flow_names_with_setup ()
24+ remaining_persisted_flow_names = set (persisted_flow_names )
25+
26+ has_missing_setup = False
27+ has_extra_setup = False
28+
29+ for name in current_flow_names :
30+ if name in remaining_persisted_flow_names :
31+ remaining_persisted_flow_names .remove (name )
32+ suffix = ''
33+ else :
34+ suffix = ' [+]'
35+ has_missing_setup = True
36+ click .echo (f'{ name } { suffix } ' )
37+
38+ if show_all :
39+ for name in persisted_flow_names :
40+ if name in remaining_persisted_flow_names :
41+ click .echo (f'{ name } [?]' )
42+ has_extra_setup = True
43+
44+ if has_missing_setup or has_extra_setup :
45+ click .echo ('' )
46+ click .echo ('Notes:' )
47+ if has_missing_setup :
48+ click .echo (' [+]: Flows present in the current process, but missing setup.' )
49+ if has_extra_setup :
50+ click .echo (' [?]: Flows with persisted setup, but not in the current process.' )
2151
2252@cli .command ()
2353@click .argument ("flow_name" , type = str , required = False )
@@ -28,17 +58,41 @@ def show(flow_name: str | None):
2858 click .echo (str (_flow_by_name (flow_name )))
2959
3060@cli .command ()
61+ def setup ():
62+ """
63+ Check and apply backend setup changes for flows, including the internal and target storage
64+ (to export).
65+ """
66+ status_check = sync_setup ()
67+ click .echo (status_check )
68+ if status_check .is_up_to_date ():
69+ click .echo ("No changes need to be pushed." )
70+ return
71+ if not click .confirm (
72+ "Changes need to be pushed. Continue? [yes/N]" , default = False , show_default = False ):
73+ return
74+ apply_setup_changes (status_check )
75+
76+ @cli .command ()
77+ @click .argument ("flow_name" , type = str , nargs = - 1 )
3178@click .option (
32- "-D " , "--delete_legacy_flows " , is_flag = True , show_default = True , default = False ,
33- help = "Also check / delete flows existing before but no longer exist ." )
34- def setup ( delete_legacy_flows ):
79+ "-a " , "--all" , "drop_all " , is_flag = True , show_default = True , default = False ,
80+ help = "Drop all flows with persisted setup, even if not defined in the current process ." )
81+ def drop ( flow_name : tuple [ str , ...], drop_all : bool ):
3582 """
36- Check and apply backend setup changes for flows, including the internal and target storage (to export).
83+ Drop the backend for specified flows.
84+ If no flow is specified, all flows defined in the current process will be dropped.
3785 """
38- options = CheckSetupStatusOptions (delete_legacy_flows = delete_legacy_flows )
39- status_check = check_setup_status (options )
40- print (status_check )
86+ if drop_all :
87+ flow_names = flow_names_with_setup ()
88+ elif len (flow_name ) == 0 :
89+ flow_names = [fl .name for fl in flow .flows ()]
90+ else :
91+ flow_names = list (flow_name )
92+ status_check = drop_setup (flow_names )
93+ click .echo (status_check )
4194 if status_check .is_up_to_date ():
95+ click .echo ("No flows need to be dropped." )
4296 return
4397 if not click .confirm (
4498 "Changes need to be pushed. Continue? [yes/N]" , default = False , show_default = False ):
0 commit comments