25
25
snapshot_bitcoin_datadir ,
26
26
)
27
27
from .process import run_command , stream_command
28
+ from .status import _get_active_binaries , _get_deployed_scenarios
28
29
29
30
console = Console ()
30
31
31
32
32
33
@click .command ()
33
- @click .argument ("scenario_name" , required = False )
34
- def stop (scenario_name ):
35
- """Stop a running scenario or all scenarios"""
36
- active_scenarios = [sc .metadata .name for sc in get_mission ("commander" )]
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_deployed_scenarios ()] + [
38
+ b ["name" ] for b in _get_active_binaries ()
39
+ ]
37
40
38
- if not active_scenarios :
39
- 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]" )
40
43
return
41
44
42
- if not scenario_name :
43
- 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
+ )
44
49
table .add_column ("Number" , style = "cyan" , justify = "right" )
45
- table .add_column ("Scenario Name" , style = "green" )
50
+ table .add_column ("Name" , style = "green" )
46
51
47
- for idx , name in enumerate (active_scenarios , 1 ):
52
+ for idx , name in enumerate (all_running , 1 ):
48
53
table .add_row (str (idx ), name )
49
54
50
55
console .print (table )
51
56
52
- 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" ]
53
58
choice = Prompt .ask (
54
- "[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]" ,
55
60
choices = choices ,
56
61
show_choices = False ,
57
62
)
@@ -61,18 +66,18 @@ def stop(scenario_name):
61
66
return
62
67
elif choice == "a" :
63
68
if Confirm .ask ("[bold red]Are you sure you want to stop all scenarios?[/bold red]" ):
64
- stop_all_scenarios (active_scenarios )
69
+ stop_all_scenarios (all_running )
65
70
else :
66
71
console .print ("[bold blue]Operation cancelled.[/bold blue]" )
67
72
return
68
73
69
- scenario_name = active_scenarios [int (choice ) - 1 ]
74
+ name = all_running [int (choice ) - 1 ]
70
75
71
- if scenario_name not in active_scenarios :
72
- 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]" )
73
78
return
74
79
75
- stop_scenario (scenario_name )
80
+ stop_scenario (name )
76
81
77
82
78
83
def stop_scenario (scenario_name ):
@@ -103,6 +108,24 @@ def stop_all_scenarios(scenarios):
103
108
console .print ("[bold green]All scenarios have been stopped.[/bold green]" )
104
109
105
110
111
+ def list_active_scenarios ():
112
+ """List all active scenarios"""
113
+ active_scenarios = [c ["name" ] for c in _get_deployed_scenarios ()]
114
+ if not active_scenarios :
115
+ print ("No active scenarios found." )
116
+ return
117
+
118
+ console = Console ()
119
+ table = Table (title = "Active Scenarios" , show_header = True , header_style = "bold magenta" )
120
+ table .add_column ("Name" , style = "cyan" )
121
+ table .add_column ("Status" , style = "green" )
122
+
123
+ for scenario in active_scenarios :
124
+ table .add_row (scenario , "deployed" )
125
+
126
+ console .print (table )
127
+
128
+
106
129
@click .command ()
107
130
def down ():
108
131
"""Bring down a running warnet quickly"""
0 commit comments