Skip to content

Commit

Permalink
chore: adding CLI interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware authored and dorimedini-starkware committed Apr 9, 2024
1 parent 5548c93 commit e5680c7
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 23 deletions.
195 changes: 187 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license-file = "LICENSE"

[workspace.dependencies]
pretty_assertions = "1.2.1"
clap = { version = "4.5.4", features = ["cargo", "derive"] }

[workspace.lints.rust]
warnings = "deny"
Expand Down
3 changes: 3 additions & 0 deletions crates/committer_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ workspace = true

[dev-dependencies]
pretty_assertions.workspace = true

[dependencies]
clap.workspace = true
75 changes: 60 additions & 15 deletions crates/committer_cli/src/main.rs
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");
}
}
}

0 comments on commit e5680c7

Please sign in to comment.