Skip to content

Commit 5ac29c2

Browse files
committed
feat: cli init
1 parent c781f3c commit 5ac29c2

File tree

6 files changed

+83
-3
lines changed

6 files changed

+83
-3
lines changed

Cargo.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exclude = ["**/target", "benches/", "tests"]
1515
eth2 = { git = "https://github.com/sigp/lighthouse.git", tag = "v5.2.1" }
1616
warp_utils = { git = "https://github.com/sigp/lighthouse.git", tag = "v5.2.1" }
1717

18-
clap = "4"
18+
clap = { version = "4", features = ["derive", "env"] }
1919
futures-util = "0.3"
2020
reqwest = "0.12"
2121
serde_json = "1.0.94"
@@ -34,6 +34,7 @@ rand = "0.8.5"
3434
once_cell = "1.19.0"
3535
hex = "0.4.3"
3636
tracing-subscriber = "0.3.18"
37+
tracing-appender = "0.2.3"
3738
uuid = { version = "1.10.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
3839
warp = "0.3.2"
39-
ssz_rs = "0.9.0"
40+
ssz_rs = "0.9.0"

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# blob-archiver-rs
1+
# blob-archiver-rs
2+
This is a Rust implementation of
3+
the [Beacon Chain blob archiver](https://github.com/base-org/blob-archiver)
4+
5+
### Development
6+
```sh
7+
# Run the tests
8+
cargo test --workspace --all-features --all-targets --locked
9+
10+
# Lint the project
11+
cargo clippy --workspace --all-targets --all-features -- -D warnings
12+
13+
# Build the project
14+
cargo build --workspace --all-targets --all-features
15+
16+
```
17+
18+
#### Run Locally
19+
To run the project locally, you should first copy `.env.template` to `.env` and then modify the environment variables
20+
to your beacon client and storage backend of choice. Then you can run the project with:
21+
22+
```sh
23+
docker compose up
24+
```

bin/api/src/main.rs

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ mod api;
33
#[allow(dead_code)]
44
static INIT: std::sync::Once = std::sync::Once::new();
55

6+
use clap::Parser;
7+
68
fn main() {
79
println!("Hello, world!");
810
}
11+
12+
#[derive(Parser, Debug)]
13+
#[clap(author, version, about, long_about = None)]
14+
struct CliArgs {
15+
#[clap(short, long, value_parser, default_value = "config.toml")]
16+
config: String,
17+
18+
#[clap(short, long, action = clap::ArgAction::Count)]
19+
verbose: u8,
20+
21+
#[clap(short, long)]
22+
dry_run: bool,
23+
}

bin/archiver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ hex.workspace = true
2424
tracing-subscriber.workspace = true
2525
uuid.workspace = true
2626
warp.workspace = true
27+
tracing-appender.workspace = true
2728
blob-archiver-storage = { path = "../../crates/storage" }
2829
blob-archiver-beacon = { path = "../../crates/beacon" }
2930

bin/archiver/src/main.rs

+26
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ use again::RetryPolicy;
33
use blob_archiver_beacon::beacon_client::BeaconClientEth2;
44
use blob_archiver_beacon::blob_test_helper;
55
use blob_archiver_storage::fs::FSStorage;
6+
use clap::Parser;
67
use eth2::types::BlockId;
78
use eth2::{BeaconNodeHttpClient, SensitiveUrl, Timeouts};
9+
use serde::Serialize;
810
use std::path::PathBuf;
911
use std::str::FromStr;
1012
use std::sync::Arc;
1113
use std::time::Duration;
1214
use tokio::sync::Mutex;
1315
use tracing::log::error;
16+
use tracing_appender::rolling::{RollingFileAppender, Rotation};
1417
use tracing_subscriber::fmt;
1518
use tracing_subscriber::layer::SubscriberExt;
1619
use tracing_subscriber::util::SubscriberInitExt;
@@ -74,3 +77,26 @@ fn setup_tracing() {
7477
tracing_subscriber::registry().with(fmt::layer()).init();
7578
});
7679
}
80+
81+
#[allow(dead_code)]
82+
fn setup_logging() {
83+
// Create a rolling file appender
84+
let file_appender = RollingFileAppender::new(Rotation::DAILY, "logs/", "app.log");
85+
86+
// Create a subscriber that uses the rolling file appender
87+
let subscriber = tracing_subscriber::registry()
88+
.with(fmt::Layer::new().with_writer(file_appender))
89+
.with(tracing_subscriber::EnvFilter::from_default_env());
90+
91+
// Set the subscriber as the global default
92+
tracing::subscriber::set_global_default(subscriber).expect("Failed to set subscriber");
93+
}
94+
95+
#[derive(Parser, Serialize)]
96+
struct CliArgs {
97+
#[clap(short, long, action = clap::ArgAction::Count, default_value = "3")]
98+
verbose: u8,
99+
100+
#[clap(short, long, default_value = "logs")]
101+
log_dir: Option<String>,
102+
}

0 commit comments

Comments
 (0)