Skip to content

Commit f0b94d2

Browse files
committed
enable stop for binaries
1 parent 4297712 commit f0b94d2

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

src/warnet/control.py

+40-17
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,38 @@
2525
snapshot_bitcoin_datadir,
2626
)
2727
from .process import run_command, stream_command
28+
from .status import _get_active_binaries, _get_deployed_scenarios
2829

2930
console = Console()
3031

3132

3233
@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+
]
3740

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]")
4043
return
4144

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+
)
4449
table.add_column("Number", style="cyan", justify="right")
45-
table.add_column("Scenario Name", style="green")
50+
table.add_column("Name", style="green")
4651

47-
for idx, name in enumerate(active_scenarios, 1):
52+
for idx, name in enumerate(all_running, 1):
4853
table.add_row(str(idx), name)
4954

5055
console.print(table)
5156

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"]
5358
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]",
5560
choices=choices,
5661
show_choices=False,
5762
)
@@ -61,18 +66,18 @@ def stop(scenario_name):
6166
return
6267
elif choice == "a":
6368
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)
6570
else:
6671
console.print("[bold blue]Operation cancelled.[/bold blue]")
6772
return
6873

69-
scenario_name = active_scenarios[int(choice) - 1]
74+
name = all_running[int(choice) - 1]
7075

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]")
7378
return
7479

75-
stop_scenario(scenario_name)
80+
stop_scenario(name)
7681

7782

7883
def stop_scenario(scenario_name):
@@ -103,6 +108,24 @@ def stop_all_scenarios(scenarios):
103108
console.print("[bold green]All scenarios have been stopped.[/bold green]")
104109

105110

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+
106129
@click.command()
107130
def down():
108131
"""Bring down a running warnet quickly"""

0 commit comments

Comments
 (0)