Skip to content

Commit 28f1861

Browse files
committed
Fix bugs in the CLI entry module.
1 parent 09250a1 commit 28f1861

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

simulaqron/cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from simulaqron.settings import simulaqron_settings, network_config
1515
from simulaqron.settings.network_config import (NodeConfig, DEFAULT_SIMULAQRON_NETWORK_FILENAME,
1616
get_default_network_config_file)
17-
from simulaqron.settings.simulaqron_config import SimBackend
17+
from simulaqron.settings.simulaqron_config import SimBackend, get_default_simulaqron_config_file
1818

1919
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
2020
# PID folder should be "LOCAL"
@@ -156,15 +156,15 @@ def version():
156156
"--network-config-file",
157157
help=f"Path to network config file. If not specified, uses ./{DEFAULT_SIMULAQRON_NETWORK_FILENAME} " # noqa: E131
158158
f"or ~/.simulaqron/{DEFAULT_SIMULAQRON_NETWORK_FILENAME}", # noqa: E131
159-
type=click.Path(exists=True, dir_okay=False, resolve_path=True, path_type=Path),
159+
type=click.Path(exists=False, dir_okay=False, resolve_path=True, path_type=Path),
160160
default=get_default_network_config_file()
161161
)
162162
@click.option(
163163
"--simulaqron-config-file",
164164
help=f"Use the given simulaqron config file. Defaults to the file named " # noqa: E131
165165
f"'{DEFAULT_SIMULAQRON_NETWORK_FILENAME}' on the current directory.", # noqa: E131
166-
type=click.Path(exists=True, dir_okay=False, resolve_path=True, path_type=Path),
167-
default=LOCAL_SIMULAQRON_SETTINGS
166+
type=click.Path(exists=False, dir_okay=False, resolve_path=True, path_type=Path),
167+
default=get_default_simulaqron_config_file()
168168
)
169169
@click.option(
170170
"--name",
@@ -226,7 +226,7 @@ def start(name: str, nodes: str, simulaqron_config_file: Path, network_config_fi
226226
"the --nodes argument."
227227
)
228228
for node_to_start in nodes:
229-
if node_to_start not in network_config.networks[name]:
229+
if node_to_start not in network_config.networks[name].nodes:
230230
raise click.BadOptionUsage(
231231
option_name="nodes",
232232
message=f"The node '{node_to_start}' was not found in the network named " # noqa: E713

simulaqron/settings/simulaqron_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,26 @@ def write_to_file(self, path: PathLike):
182182
with file_path.open("wt") as file:
183183
serialized = JSONSerializer.serialize(self)
184184
json.dump(serialized, file, indent=4)
185+
186+
def get_default_simulaqron_config_file():
187+
"""
188+
Get the simulaqron config file path to use.
189+
190+
:return: Path to the simulaqron config file.
191+
:rtype: Path
192+
"""
193+
# Implements using the local directory setting as a priority
194+
if LOCAL_SIMULAQRON_SETTINGS.exists():
195+
return LOCAL_SIMULAQRON_SETTINGS
196+
if HOME_SIMULAQRON_SETTINGS.exists():
197+
return HOME_SIMULAQRON_SETTINGS
198+
199+
from . import simulaqron_settings
200+
201+
# Create default in HOME (matches load_from_known_sources behavior)
202+
# XXX I have mixed feelings we should do this, but I leave it for now
203+
simulaqron_settings.default_settings()
204+
HOME_SIMULAQRON_SETTINGS.parent.mkdir(parents=True, exist_ok=True)
205+
simulaqron_settings.write_to_file(HOME_SIMULAQRON_SETTINGS)
206+
return HOME_SIMULAQRON_SETTINGS
207+

0 commit comments

Comments
 (0)