-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5548c93
commit e5680c7
Showing
4 changed files
with
251 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ workspace = true | |
|
||
[dev-dependencies] | ||
pretty_assertions.workspace = true | ||
|
||
[dependencies] | ||
clap.workspace = true |
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 |
---|---|---|
@@ -1,20 +1,65 @@ | ||
use std::env; | ||
use clap::{Args, Parser, Subcommand}; | ||
use std::path::Path; | ||
|
||
/// Committer CLI. | ||
#[derive(Debug, Parser)] | ||
#[clap(name = "committer-cli", version)] | ||
pub struct CommitterCliArgs { | ||
#[clap(flatten)] | ||
global_opts: GlobalOpts, | ||
|
||
#[clap(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
enum Command { | ||
/// Given previous state tree skeleton and a state diff, computes the new commitment. | ||
Commit { | ||
/// File path to input. | ||
#[clap(long, short = 'i', default_value = "stdin")] | ||
input_path: String, | ||
|
||
/// File path to output. | ||
#[clap(long, short = 'o', default_value = "stdout")] | ||
output_path: String, | ||
|
||
/// The version of the class hash, as a string (before conversion to raw bytes). | ||
#[clap(long)] | ||
class_hash_version: String, | ||
|
||
/// The version of the contract state hash, as a string (before conversion to raw bytes). | ||
#[clap(long)] | ||
contract_state_hash_version: String, | ||
}, | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
struct GlobalOpts {} | ||
|
||
/// Main entry point of the committer CLI. | ||
fn main() { | ||
// Open the input file. | ||
let args: Vec<String> = env::args().collect(); | ||
let input_file_name = Path::new(&args[1]); | ||
let output_file_name = Path::new(&args[2]); | ||
assert!( | ||
input_file_name.is_absolute() && output_file_name.is_absolute(), | ||
"Given paths must be absolute" | ||
); | ||
|
||
// Business logic to be implemented here. | ||
let output = std::fs::read(input_file_name).unwrap(); | ||
|
||
// Output to file. | ||
std::fs::write(output_file_name, output).expect("Failed to write output"); | ||
let args = CommitterCliArgs::parse(); | ||
|
||
match args.command { | ||
Command::Commit { | ||
input_path, | ||
output_path, | ||
class_hash_version: _, | ||
contract_state_hash_version: _, | ||
} => { | ||
let input_file_name = Path::new(&input_path); | ||
let output_file_name = Path::new(&output_path); | ||
assert!( | ||
input_file_name.is_absolute() && output_file_name.is_absolute(), | ||
"Given paths must be absolute." | ||
); | ||
|
||
// Business logic to be implemented here. | ||
let output = std::fs::read(input_file_name).unwrap(); | ||
|
||
// Output to file. | ||
std::fs::write(output_file_name, output).expect("Failed to write output"); | ||
} | ||
} | ||
} |