From 631745bce362e53af7662e9a9c4c7f236b21ad8b Mon Sep 17 00:00:00 2001
From: willcl-ark <will@256k1.dev>
Date: Tue, 8 Oct 2024 12:02:02 +0100
Subject: [PATCH 1/2] add inquirer option to set pullPolicy

---
 src/warnet/graph.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/warnet/graph.py b/src/warnet/graph.py
index 390686486..79811ef8a 100644
--- a/src/warnet/graph.py
+++ b/src/warnet/graph.py
@@ -25,6 +25,7 @@ def custom_graph(
     fork_obs_query_interval: int,
     caddy: bool,
     logging: bool,
+    force_pull: bool
 ):
     try:
         datadir.mkdir(parents=False, exist_ok=False)
@@ -83,6 +84,10 @@ def custom_graph(
     # Configure logging
     defaults_yaml_content["collectLogs"] = logging
 
+    # Set pullPolicy
+    if force_pull:
+        defaults_yaml_content["image"]["pullPolicy"] = "Always"
+
     with open(os.path.join(datadir, "node-defaults.yaml"), "w") as f:
         yaml.dump(defaults_yaml_content, f, default_flow_style=False, sort_keys=False)
 
@@ -123,6 +128,14 @@ def inquirer_create_network(project_path: Path):
             choices=SUPPORTED_TAGS,
             default=DEFAULT_TAG,
         ),
+
+        inquirer.Confirm(
+            "force_pull",
+            message=click.style(
+                "Would you like to force-pull bitcoin node images from dockerhub?", fg="blue", bold=True
+            ),
+            default=False,
+        ),
     ]
 
     net_answers = inquirer.prompt(questions)
@@ -197,6 +210,7 @@ def inquirer_create_network(project_path: Path):
         fork_observer_query_interval,
         caddy,
         logging,
+        net_answers["force_pull"],
     )
     return custom_network_path
 

From 711156a73898eda58a2e306fcc21a58356966d95 Mon Sep 17 00:00:00 2001
From: willcl-ark <will@256k1.dev>
Date: Tue, 8 Oct 2024 12:14:42 +0100
Subject: [PATCH 2/2] fix inquirer asking questions out of order

---
 src/warnet/graph.py | 155 ++++++++++++++++++--------------------------
 test/graph_test.py  |   4 +-
 2 files changed, 66 insertions(+), 93 deletions(-)

diff --git a/src/warnet/graph.py b/src/warnet/graph.py
index 79811ef8a..288c1d74d 100644
--- a/src/warnet/graph.py
+++ b/src/warnet/graph.py
@@ -25,7 +25,7 @@ def custom_graph(
     fork_obs_query_interval: int,
     caddy: bool,
     logging: bool,
-    force_pull: bool
+    force_pull: bool,
 ):
     try:
         datadir.mkdir(parents=False, exist_ok=False)
@@ -98,119 +98,90 @@ def custom_graph(
 
 def inquirer_create_network(project_path: Path):
     # Custom network configuration
-    questions = [
-        inquirer.Text(
-            "network_name",
-            message=click.style("Enter your network name", fg="blue", bold=True),
-            validate=lambda _, x: len(x) > 0,
-        ),
-        inquirer.List(
-            "nodes",
-            message=click.style("How many nodes would you like?", fg="blue", bold=True),
-            choices=["8", "12", "20", "50", "other"],
-            default="12",
-        ),
-        inquirer.List(
-            "connections",
-            message=click.style(
-                "How many connections would you like each node to have?",
-                fg="blue",
-                bold=True,
-            ),
-            choices=["0", "1", "2", "8", "12", "other"],
-            default="8",
+    network_name = inquirer.text(
+        message=click.style("Enter your network name", fg="blue", bold=True),
+        validate=lambda _, x: len(x) > 0,
+    )
+    nodes = inquirer.list_input(
+        message=click.style("How many nodes would you like?", fg="blue", bold=True),
+        choices=["8", "12", "20", "50", "other"],
+        default="12",
+    )
+    if nodes == "other":
+        nodes = inquirer.text(
+            message=click.style("Enter the number of nodes", fg="blue", bold=True),
+            validate=lambda _, x: int(x) > 0,
+        )
+    connections = inquirer.list_input(
+        message=click.style(
+            "How many connections would you like each node to have?",
+            fg="blue",
+            bold=True,
         ),
-        inquirer.List(
-            "version",
-            message=click.style(
-                "Which version would you like nodes to run by default?", fg="blue", bold=True
-            ),
-            choices=SUPPORTED_TAGS,
-            default=DEFAULT_TAG,
+        choices=["0", "1", "2", "8", "12", "other"],
+        default="8",
+    )
+    if connections == "other":
+        connections = inquirer.text(
+            message=click.style("Enter the number of connections", fg="blue", bold=True),
+            validate=lambda _, x: int(x) >= 0,
+        )
+    version = inquirer.list_input(
+        message=click.style(
+            "Which version would you like nodes to run by default?", fg="blue", bold=True
         ),
-
-        inquirer.Confirm(
-            "force_pull",
-            message=click.style(
-                "Would you like to force-pull bitcoin node images from dockerhub?", fg="blue", bold=True
-            ),
-            default=False,
+        choices=SUPPORTED_TAGS,
+        default=DEFAULT_TAG,
+    )
+    force_pull = inquirer.confirm(
+        message=click.style(
+            "Would you like to force-pull bitcoin node images from dockerhub?", fg="blue", bold=True
         ),
-    ]
-
-    net_answers = inquirer.prompt(questions)
-    if net_answers is None:
-        click.secho("Setup cancelled by user.", fg="yellow")
-        return False
+        default=False,
+    )
 
-    if net_answers["nodes"] == "other":
-        custom_nodes = inquirer.prompt(
-            [
-                inquirer.Text(
-                    "nodes",
-                    message=click.style("Enter the number of nodes", fg="blue", bold=True),
-                    validate=lambda _, x: int(x) > 0,
-                )
-            ]
-        )
-        if custom_nodes is None:
-            click.secho("Setup cancelled by user.", fg="yellow")
-            return False
-        net_answers["nodes"] = custom_nodes["nodes"]
-
-    if net_answers["connections"] == "other":
-        custom_connections = inquirer.prompt(
-            [
-                inquirer.Text(
-                    "connections",
-                    message=click.style("Enter the number of connections", fg="blue", bold=True),
-                    validate=lambda _, x: int(x) >= 0,
-                )
-            ]
-        )
-        if custom_connections is None:
-            click.secho("Setup cancelled by user.", fg="yellow")
-            return False
-        net_answers["connections"] = custom_connections["connections"]
-    fork_observer = click.prompt(
-        click.style(
-            "\nWould you like to enable fork-observer on the network?", fg="blue", bold=True
+    # Inquire about fork observer
+    fork_observer = inquirer.confirm(
+        message=click.style(
+            "Would you like to enable fork-observer on the network?", fg="blue", bold=True
         ),
-        type=bool,
         default=True,
     )
     fork_observer_query_interval = 20
     if fork_observer:
-        fork_observer_query_interval = click.prompt(
-            click.style(
-                "\nHow often would you like fork-observer to query node status (seconds)?",
-                fg="blue",
-                bold=True,
-            ),
-            type=int,
-            default=20,
+        fork_observer_query_interval = int(
+            inquirer.text(
+                message=click.style(
+                    "How often would you like fork-observer to query node status (seconds)?",
+                    fg="blue",
+                    bold=True,
+                ),
+                validate=lambda _, x: int(x) > 0,
+                default=fork_observer_query_interval,
+            )
         )
 
-    logging = click.prompt(
-        click.style(
-            "\nWould you like to enable grafana logging on the network?", fg="blue", bold=True
+    # Inquire about logging
+    logging = inquirer.confirm(
+        message=click.style(
+            "Would you like to enable grafana logging on the network?", fg="blue", bold=True
         ),
-        type=bool,
         default=False,
     )
+
     caddy = fork_observer | logging
-    custom_network_path = project_path / "networks" / net_answers["network_name"]
+    custom_network_path = project_path / "networks" / network_name
     click.secho("\nGenerating custom network...", fg="yellow", bold=True)
     custom_graph(
-        int(net_answers["nodes"]),
-        int(net_answers["connections"]),
-        net_answers["version"],
+        int(nodes),
+        int(connections),
+        version,
         custom_network_path,
         fork_observer,
         fork_observer_query_interval,
         caddy,
         logging,
-        net_answers["force_pull"],
+        force_pull,
     )
     return custom_network_path
 
diff --git a/test/graph_test.py b/test/graph_test.py
index 3d0ad5848..8964d8859 100755
--- a/test/graph_test.py
+++ b/test/graph_test.py
@@ -45,9 +45,11 @@ def directory_exists(self):
             self.sut.sendline("")
             self.sut.expect("version", timeout=10)
             self.sut.sendline("")
+            self.sut.expect("force-pull", timeout=10)
+            self.sut.sendline("")
             self.sut.expect("enable fork-observer", timeout=10)
             self.sut.sendline("")
-            self.sut.expect("seconds", timeout=10)
+            self.sut.expect("query node status", timeout=10)
             self.sut.sendline("")
             self.sut.expect("enable grafana", timeout=10)
             self.sut.sendline("")