Skip to content

Commit 734fbb3

Browse files
committed
improve quickstart colours, add defaults
1 parent ca5b046 commit 734fbb3

File tree

1 file changed

+63
-32
lines changed

1 file changed

+63
-32
lines changed

Diff for: src/warnet/main.py

+63-32
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import click
99
import yaml
10-
from rich import print as richprint
1110

1211
from .admin import admin
1312
from .bitcoin import bitcoin
@@ -17,7 +16,7 @@
1716
from .image import image
1817
from .network import copy_network_defaults, copy_scenario_defaults
1918
from .status import status as status_command
20-
from .util import SUPPORTED_TAGS
19+
from .util import DEFAULT_TAG, SUPPORTED_TAGS
2120

2221
QUICK_START_PATH = files("resources.scripts").joinpath("quick_start.sh")
2322

@@ -54,62 +53,92 @@ def quickstart():
5453
process.stdout.close()
5554
return_code = process.wait()
5655
if return_code != 0:
57-
click.echo(f"Quick start script failed with return code {return_code}")
58-
click.echo("Install missing requirements before proceeding")
56+
click.secho(
57+
f"Quick start script failed with return code {return_code}", fg="red", bold=True
58+
)
59+
click.secho("Install missing requirements before proceeding", fg="yellow")
5960
return False
6061

61-
create_project = click.confirm("Do you want to create a new project?", default=True)
62+
create_project = click.confirm(
63+
click.style("\nDo you want to create a new project?", fg="blue", bold=True),
64+
default=True,
65+
)
6266
if not create_project:
63-
click.echo("Setup completed successfully!")
67+
click.secho("\nSetup completed successfully!", fg="green", bold=True)
6468
return True
6569

6670
default_path = os.path.abspath(os.getcwd())
6771
project_path = click.prompt(
68-
"Enter the project directory path",
72+
click.style("\nEnter the project directory path", fg="blue", bold=True),
6973
default=default_path,
7074
type=click.Path(file_okay=False, dir_okay=True, resolve_path=True),
7175
)
7276

73-
custom_network = click.confirm("Do you want to create a custom network?", default=True)
77+
custom_network = click.confirm(
78+
click.style("\nDo you want to create a custom network?", fg="blue", bold=True),
79+
default=True,
80+
)
7481
if not custom_network:
7582
create_warnet_project(Path(project_path))
76-
click.echo("Setup completed successfully!")
83+
click.secho("\nSetup completed successfully!", fg="green", bold=True)
7784
return True
7885

7986
network_name = click.prompt(
80-
"Enter the network name",
87+
click.style("\nEnter the network name", fg="blue", bold=True),
8188
type=str,
8289
)
83-
nodes = click.prompt("How many nodes would you like?", type=int)
84-
connections = click.prompt("How many connects would you like each node to have?", type=int)
90+
91+
nodes = click.prompt(
92+
click.style("\nHow many nodes would you like?", fg="blue", bold=True),
93+
type=int,
94+
default=15,
95+
)
96+
connections = click.prompt(
97+
click.style(
98+
"\nHow many connections would you like each node to have?", fg="blue", bold=True
99+
),
100+
type=int,
101+
default=8,
102+
)
85103
version = click.prompt(
86-
"Which version would you like nodes to have by default?",
104+
click.style(
105+
"\nWhich version would you like nodes to be by default?", fg="blue", bold=True
106+
),
87107
type=click.Choice(SUPPORTED_TAGS, case_sensitive=False),
108+
default=DEFAULT_TAG,
88109
)
89110

111+
click.secho("\nCreating project structure...", fg="yellow", bold=True)
90112
create_warnet_project(Path(project_path))
91-
custom_graph(nodes, connections, version, Path(project_path) / "networks" / network_name)
92-
113+
click.secho("\nGenerating custom network...", fg="yellow", bold=True)
114+
custom_network_path = Path(project_path) / "networks" / network_name
115+
custom_graph(nodes, connections, version, custom_network_path)
116+
click.secho("\nSetup completed successfully!", fg="green", bold=True)
117+
click.echo("\nRun the following command to deploy this network:")
118+
click.echo(f"warcli deploy {custom_network_path}")
93119
except Exception as e:
94-
print(f"An error occurred while running the quick start script:\n\n{e}\n\n")
95-
print("Please report this to https://github.com/bitcoin-dev-project/warnet/issues")
120+
click.secho(f"An error occurred while running the quick start script:\n\n{e}\n\n", fg="red")
121+
click.secho(
122+
"Please report this to https://github.com/bitcoin-dev-project/warnet/issues",
123+
fg="yellow",
124+
)
96125
return False
97126

98127

99128
def create_warnet_project(directory: Path, check_empty: bool = False):
100129
"""Common function to create a warnet project"""
101130
if check_empty and any(directory.iterdir()):
102-
richprint("[yellow]Warning: Directory is not empty[/yellow]")
131+
click.secho("Warning: Directory is not empty", fg="yellow")
103132
if not click.confirm("Do you want to continue?", default=True):
104133
return
105134

106135
try:
107136
copy_network_defaults(directory)
108137
copy_scenario_defaults(directory)
109-
richprint(f"[green]Copied network example files to {directory / 'networks'}[/green]")
110-
richprint(f"[green]Created warnet project structure in {directory}[/green]")
138+
click.echo(f"Copied network example files to {directory}/networks")
139+
click.echo(f"Created warnet project structure in {directory}")
111140
except Exception as e:
112-
richprint(f"[red]Error creating project: {e}[/red]")
141+
click.secho(f"Error creating project: {e}", fg="red")
113142
raise e
114143

115144

@@ -120,7 +149,7 @@ def create_warnet_project(directory: Path, check_empty: bool = False):
120149
def create(directory: Path):
121150
"""Create a new warnet project in the specified directory"""
122151
if directory.exists():
123-
richprint(f"[red]Error: Directory {directory} already exists[/red]")
152+
click.secho(f"Error: Directory {directory} already exists", fg="red")
124153
return
125154
create_warnet_project(directory)
126155

@@ -155,17 +184,17 @@ def auth(kube_config: str) -> None:
155184
flatten_cmd, shell=True, check=True, capture_output=True, text=True
156185
)
157186
except subprocess.CalledProcessError as e:
158-
print("Error occurred while executing kubectl config view --flatten:")
159-
print(e.stderr)
187+
click.secho("Error occurred while executing kubectl config view --flatten:", fg="red")
188+
click.secho(e.stderr, fg="red")
160189
sys.exit(1)
161190

162191
if result_flatten.returncode == 0:
163192
with open(current_kubeconfig, "w") as file:
164193
file.write(result_flatten.stdout)
165-
print(f"Authorization file written to: {current_kubeconfig}")
194+
click.secho(f"Authorization file written to: {current_kubeconfig}", fg="green")
166195
else:
167-
print("Could not create authorization file")
168-
print(result_flatten.stderr)
196+
click.secho("Could not create authorization file", fg="red")
197+
click.secho(result_flatten.stderr, fg="red")
169198
sys.exit(result_flatten.returncode)
170199

171200
try:
@@ -174,12 +203,12 @@ def auth(kube_config: str) -> None:
174203
update_cmd, shell=True, check=True, capture_output=True, text=True
175204
)
176205
if result_update.returncode != 0:
177-
print("Could not update authorization file")
178-
print(result_flatten.stderr)
206+
click.secho("Could not update authorization file", fg="red")
207+
click.secho(result_flatten.stderr, fg="red")
179208
sys.exit(result_flatten.returncode)
180209
except subprocess.CalledProcessError as e:
181-
print("Error occurred while executing kubectl config view --flatten:")
182-
print(e.stderr)
210+
click.secho("Error occurred while executing kubectl config view --flatten:", fg="red")
211+
click.secho(e.stderr, fg="red")
183212
sys.exit(1)
184213

185214
with open(current_kubeconfig) as file:
@@ -191,7 +220,9 @@ def auth(kube_config: str) -> None:
191220

192221
with open(current_kubeconfig) as file:
193222
contents = yaml.safe_load(file)
194-
print(f"\nWarcli's current context is now set to: {contents['current-context']}")
223+
click.secho(
224+
f"\nWarcli's current context is now set to: {contents['current-context']}", fg="green"
225+
)
195226

196227

197228
if __name__ == "__main__":

0 commit comments

Comments
 (0)