-
Notifications
You must be signed in to change notification settings - Fork 76
Proxy nile node
unknown options to starknet-devnet
#342
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
from nile.core.clean import clean as clean_command | ||
from nile.core.compile import compile as compile_command | ||
from nile.core.init import init as init_command | ||
from nile.core.node import get_help_message | ||
from nile.core.node import node as node_command | ||
from nile.core.plugins import load_plugins | ||
from nile.core.run import run as run_command | ||
|
@@ -352,28 +353,27 @@ def clean(ctx): | |
clean_command() | ||
|
||
|
||
@cli.command() | ||
@click.option("--host", default="127.0.0.1") | ||
@click.option("--port", default=5050) | ||
@click.option("--seed", type=int) | ||
@click.option("--lite_mode", is_flag=True) | ||
@enable_stack_trace | ||
def node(ctx, host, port, seed, lite_mode): | ||
"""Start StarkNet local network. | ||
|
||
$ nile node | ||
Start StarkNet local network at port 5050 | ||
class NodeCommand(click.Command): | ||
"""Command wrapper to override the default help message.""" | ||
Comment on lines
+357
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
$ nile node --host HOST --port 5001 | ||
Start StarkNet network on address HOST listening at port 5001 | ||
def format_help(self, ctx, formatter): | ||
"""Help message override.""" | ||
click.echo(get_help_message()) | ||
|
||
$ nile node --seed SEED | ||
Start StarkNet local network with seed SEED | ||
|
||
$ nile node --lite_mode | ||
Start StarkNet network on lite-mode | ||
""" | ||
node_command(host, port, seed, lite_mode) | ||
@cli.command( | ||
context_settings=dict( | ||
ignore_unknown_options=True, | ||
), | ||
cls=NodeCommand, | ||
) | ||
@click.option("--host", default="127.0.0.1") | ||
@click.option("--port", default=5050) | ||
@click.argument("node_args", nargs=-1, type=click.UNPROCESSED) | ||
@enable_stack_trace | ||
def node(ctx, host, port, node_args): | ||
"""Start StarkNet local network.""" | ||
node_command(host, port, node_args) | ||
|
||
|
||
@cli.command() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
from nile.common import DEFAULT_GATEWAYS, write_node_json | ||
|
||
|
||
def node(host="127.0.0.1", port=5050, seed=None, lite_mode=False): | ||
def node(host="127.0.0.1", port=5050, node_args=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wanted to let the defaults in our control, but if they match I agree it makes sense to remove them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought. I will let the host and port options as a commodity if you agree because we are using them here:
And if we remove them, I would need to parse the node_args to get the values anyway (is easier to catch them separately as we are currently doing). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh right! Yeah, leaving them in sounds good to me. Depending on how the Nile config turns out down the road, maybe we can revisit this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. |
||
"""Start StarkNet local network.""" | ||
try: | ||
# Save host and port information to be used by other commands | ||
|
@@ -19,13 +19,8 @@ def node(host="127.0.0.1", port=5050, seed=None, lite_mode=False): | |
write_node_json(network, gateway_url) | ||
|
||
command = ["starknet-devnet", "--host", host, "--port", str(port)] | ||
|
||
if seed is not None: | ||
command.append("--seed") | ||
command.append(str(seed)) | ||
|
||
if lite_mode: | ||
command.append("--lite-mode") | ||
if node_args is not None: | ||
command += list(node_args) | ||
|
||
# Start network | ||
subprocess.check_call(command) | ||
|
@@ -35,3 +30,21 @@ def node(host="127.0.0.1", port=5050, seed=None, lite_mode=False): | |
"\n\n😰 Could not find starknet-devnet, is it installed? Try with:\n" | ||
" pip install starknet-devnet" | ||
) | ||
|
||
|
||
def get_help_message(): | ||
"""Retrieve and parse the help message from starknet-devnet.""" | ||
base = """ | ||
Start StarkNet local network. | ||
|
||
$ nile node | ||
Start StarkNet local network at port 5050 | ||
|
||
Options: | ||
""" | ||
|
||
raw_message = subprocess.check_output(["starknet-devnet", "--help"]).decode("utf-8") | ||
options_index = raw_message.find("optional arguments:") | ||
options = raw_message[options_index + 19 :] | ||
|
||
return base + options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bit overkill. We're basically saying the same thing below with
Starknet Devnet Options
. I'm thinking we can remove the note here. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it, removed it, and added it again a couple of times thinking about the design. I'm not too comfortable 100 percent with either of the versions, because I wanted to let it as clear as possible for the user that he can use these arguments from starknet-devnet, but not adding all of them here. At the same time, I feel the user can check the command doc in a quick glance and miss this "Starknet Devnet Options".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with removing the note, but I still have the feeling the user can miss this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha yeah, I see the dilemma. If we remove
host
andport
, there's much less noise around thenode
section. I think it's enough, no? Here's a crude example of how I'm seeing it:node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I think that should be enough indeed.