-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce CLI command #5
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use clap::{arg, value_parser, Command}; | ||
|
||
fn cli() -> Command { | ||
Command::new("state-reconstruct") | ||
.about("zkSync state reconstruction tool") | ||
.subcommand_required(true) | ||
.arg_required_else_help(false) | ||
.subcommand( | ||
Command::new("reconstruct") | ||
.about("Reconstruct L2 state") | ||
.subcommand_required(true) | ||
.subcommand( | ||
Command::new("l1") | ||
.about("Read state from Ethereum L1") | ||
.arg( | ||
arg!(--"start-block" <START_BLOCK>) | ||
.help("Ethereum block number to start state import from") | ||
.default_value(state_reconstruct::GENESIS_BLOCK.to_string()) | ||
.value_parser(value_parser!(u64)), | ||
) | ||
.arg( | ||
arg!(--"block-step" <BLOCK_STEP>) | ||
.help("Number of blocks to filter & process in one step") | ||
.default_value(state_reconstruct::BLOCK_STEP.to_string()) | ||
.value_parser(value_parser!(u64)), | ||
), | ||
) | ||
.subcommand( | ||
Command::new("file") | ||
.about("Read state from file") | ||
.arg(arg!(<FILE> "File to import state from")) | ||
.arg_required_else_help(true), | ||
), | ||
) | ||
} | ||
|
||
fn main() { | ||
let matches = cli().get_matches(); | ||
|
||
match matches.subcommand() { | ||
Some(("reconstruct", sub_matches)) => { | ||
match sub_matches.subcommand() { | ||
Some(("l1", args)) => { | ||
let start_block = args.get_one::<u64>("start-block").expect("required"); | ||
let block_step = args.get_one::<u64>("block-step").expect("required"); | ||
println!("reconstruct from L1, starting from block number {}, processing {} blocks at a time", start_block, block_step); | ||
// TODO(tuommaki): Implement block fetch logic. | ||
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'll build this in small steps 🙂 |
||
} | ||
Some(("file", args)) => { | ||
let input_file = args.get_one::<String>("FILE").expect("required"); | ||
println!("reconstruct from file (path: \"{}\")", input_file); | ||
} | ||
_ => unreachable!(), | ||
} | ||
} | ||
_ => unreachable!(), | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 choose the builder style since I don't anticipate that many sub-commands or arguments and they are pretty self-descriptive this way.
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.
Gotcha, to be honest I'm not a huge fan of the builder style in general since I think it's a lot harder to understand how everything relates even when we don't have a lot of commands. However, if it's what you prefer I'm fine with it - I know that I'll be integrating database source arguments, but other than that I can't imagine many more arguments/sub-commands for now.