25
25
snapshot_bitcoin_datadir ,
26
26
)
27
27
from .process import run_command , stream_command
28
+ from .status import _get_active_binaries , _get_active_scenarios
28
29
29
30
console = Console ()
30
31
31
32
32
- def get_active_scenarios ():
33
- """Get list of active scenarios"""
34
- commanders = get_mission ("commander" )
35
- return [c .metadata .name for c in commanders ]
36
-
37
-
38
33
@click .command ()
39
- @click .argument ("scenario_name" , required = False )
40
- def stop (scenario_name ):
41
- """Stop a running scenario or all scenarios"""
42
- active_scenarios = get_active_scenarios ()
34
+ @click .argument ("name" , required = False )
35
+ def stop (name ):
36
+ """Stop one or all running scenarios or binaries"""
37
+ all_running = [c ["name" ] for c in _get_active_scenarios ()] + [
38
+ b ["name" ] for b in _get_active_binaries ()
39
+ ]
43
40
44
- if not active_scenarios :
45
- console .print ("[bold red]No active scenarios found.[/bold red]" )
41
+ if not all_running :
42
+ console .print ("[bold red]No active scenarios or binaries found.[/bold red]" )
46
43
return
47
44
48
- if not scenario_name :
49
- table = Table (title = "Active Scenarios" , show_header = True , header_style = "bold magenta" )
45
+ if not name :
46
+ table = Table (
47
+ title = "Active Scenarios & binaries" , show_header = True , header_style = "bold magenta"
48
+ )
50
49
table .add_column ("Number" , style = "cyan" , justify = "right" )
51
- table .add_column ("Scenario Name" , style = "green" )
50
+ table .add_column ("Name" , style = "green" )
52
51
53
- for idx , name in enumerate (active_scenarios , 1 ):
52
+ for idx , name in enumerate (all_running , 1 ):
54
53
table .add_row (str (idx ), name )
55
54
56
55
console .print (table )
57
56
58
- choices = [str (i ) for i in range (1 , len (active_scenarios ) + 1 )] + ["a" , "q" ]
57
+ choices = [str (i ) for i in range (1 , len (all_running ) + 1 )] + ["a" , "q" ]
59
58
choice = Prompt .ask (
60
- "[bold yellow]Enter the number of the scenario to stop, 'a' to stop all, or 'q' to quit[/bold yellow]" ,
59
+ "[bold yellow]Enter the number you want to stop, 'a' to stop all, or 'q' to quit[/bold yellow]" ,
61
60
choices = choices ,
62
61
show_choices = False ,
63
62
)
@@ -67,18 +66,18 @@ def stop(scenario_name):
67
66
return
68
67
elif choice == "a" :
69
68
if Confirm .ask ("[bold red]Are you sure you want to stop all scenarios?[/bold red]" ):
70
- stop_all_scenarios (active_scenarios )
69
+ stop_all_scenarios (all_running )
71
70
else :
72
71
console .print ("[bold blue]Operation cancelled.[/bold blue]" )
73
72
return
74
73
75
- scenario_name = active_scenarios [int (choice ) - 1 ]
74
+ name = all_running [int (choice ) - 1 ]
76
75
77
- if scenario_name not in active_scenarios :
78
- console .print (f"[bold red]No active scenario found with name: { scenario_name } [/bold red]" )
76
+ if name not in all_running :
77
+ console .print (f"[bold red]No active scenario or binary found with name: { name } [/bold red]" )
79
78
return
80
79
81
- stop_scenario (scenario_name )
80
+ stop_scenario (name )
82
81
83
82
84
83
def stop_scenario (scenario_name ):
@@ -111,7 +110,7 @@ def stop_all_scenarios(scenarios):
111
110
112
111
def list_active_scenarios ():
113
112
"""List all active scenarios"""
114
- active_scenarios = get_active_scenarios ()
113
+ active_scenarios = [ c [ "name" ] for c in _get_active_scenarios ()]
115
114
if not active_scenarios :
116
115
print ("No active scenarios found." )
117
116
return
0 commit comments