Skip to content

Commit 5389c32

Browse files
kariyclaude
andauthored
refactor(cli): rename --db-dir to --data-dir (#407)
Renames the `--db-dir` CLI flag to `--data-dir` while keeping `--db-dir` as an alias for backward compatibility. Config files also accept both `data_dir` and `db_dir` keys. The `katana-node-bindings` crate adds a new `data_dir()` method and deprecates `db_dir()`. --- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 54d81ad commit 5389c32

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

crates/cli/src/args.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ pub struct SequencerNodeArgs {
7171
///
7272
/// The path must either be an empty directory or a directory which already contains a
7373
/// previously initialized Katana database.
74-
#[arg(long)]
74+
#[arg(long, alias = "db-dir")]
7575
#[arg(value_name = "PATH")]
76-
pub db_dir: Option<PathBuf>,
76+
pub data_dir: Option<PathBuf>,
7777

7878
/// Configuration file
7979
#[arg(long)]
@@ -415,7 +415,7 @@ impl SequencerNodeArgs {
415415
}
416416

417417
fn db_config(&self) -> DbConfig {
418-
DbConfig { dir: self.db_dir.clone() }
418+
DbConfig { dir: self.data_dir.clone() }
419419
}
420420

421421
fn metrics_config(&self) -> Option<MetricsConfig> {
@@ -483,8 +483,8 @@ impl SequencerNodeArgs {
483483
self.block_time = config.block_time;
484484
}
485485

486-
if self.db_dir.is_none() {
487-
self.db_dir = config.db_dir;
486+
if self.data_dir.is_none() {
487+
self.data_dir = config.data_dir;
488488
}
489489

490490
if self.logging == LoggingOptions::default() {
@@ -591,7 +591,7 @@ mod test {
591591
"200",
592592
"--validate-max-steps",
593593
"100",
594-
"--db-dir",
594+
"--data-dir",
595595
"/path/to/db",
596596
]);
597597
let config = args.config().unwrap();
@@ -605,6 +605,14 @@ mod test {
605605
assert_eq!(config.chain.genesis().sequencer_address, *DEFAULT_SEQUENCER_ADDRESS);
606606
}
607607

608+
#[test]
609+
fn test_db_dir_alias() {
610+
// --db-dir should work as an alias for --data-dir
611+
let args = SequencerNodeArgs::parse_from(["katana", "--db-dir", "/path/to/db"]);
612+
let config = args.config().unwrap();
613+
assert_eq!(config.db.dir, Some(PathBuf::from("/path/to/db")));
614+
}
615+
608616
#[test]
609617
fn custom_fixed_gas_prices() {
610618
let config = SequencerNodeArgs::parse_from(["katana"]).config().unwrap();

crates/cli/src/file.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub struct NodeArgsConfig {
1313
pub no_mining: Option<bool>,
1414
pub block_time: Option<u64>,
1515
pub block_cairo_steps_limit: Option<u64>,
16-
pub db_dir: Option<PathBuf>,
16+
#[serde(alias = "db_dir")]
17+
pub data_dir: Option<PathBuf>,
1718
pub messaging: Option<MessagingConfig>,
1819
pub logging: Option<LoggingOptions>,
1920
pub starknet: Option<StarknetOptions>,
@@ -49,7 +50,7 @@ impl TryFrom<SequencerNodeArgs> for NodeArgsConfig {
4950
no_mining: if args.no_mining { Some(true) } else { None },
5051
block_time: args.block_time,
5152
block_cairo_steps_limit: args.block_cairo_steps_limit,
52-
db_dir: args.db_dir,
53+
data_dir: args.data_dir,
5354
messaging: args.messaging,
5455
..Default::default()
5556
};

crates/node-bindings/src/lib.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pub struct Katana {
177177
no_mining: bool,
178178
json_log: bool,
179179
block_time: Option<u64>,
180-
db_dir: Option<PathBuf>,
180+
data_dir: Option<PathBuf>,
181181
l1_provider: Option<String>,
182182
fork_block_number: Option<u64>,
183183
messaging: Option<PathBuf>,
@@ -273,12 +273,18 @@ impl Katana {
273273
self
274274
}
275275

276-
/// Sets the database directory path which will be used when the `katana` instance is launched.
277-
pub fn db_dir<T: Into<PathBuf>>(mut self, db_dir: T) -> Self {
278-
self.db_dir = Some(db_dir.into());
276+
/// Sets the data directory path which will be used when the `katana` instance is launched.
277+
pub fn data_dir<T: Into<PathBuf>>(mut self, data_dir: T) -> Self {
278+
self.data_dir = Some(data_dir.into());
279279
self
280280
}
281281

282+
/// Sets the data directory path which will be used when the `katana` instance is launched.
283+
#[deprecated(note = "Use `data_dir` instead")]
284+
pub fn db_dir<T: Into<PathBuf>>(self, db_dir: T) -> Self {
285+
self.data_dir(db_dir)
286+
}
287+
282288
/// Sets the RPC URL to fork the network from.
283289
pub fn l1_provider<T: Into<String>>(mut self, rpc_url: T) -> Self {
284290
self.l1_provider = Some(rpc_url.into());
@@ -458,8 +464,8 @@ impl Katana {
458464
cmd.arg("-b").arg(block_time.to_string());
459465
}
460466

461-
if let Some(db_dir) = self.db_dir {
462-
cmd.arg("--db-dir").arg(db_dir);
467+
if let Some(data_dir) = self.data_dir {
468+
cmd.arg("--data-dir").arg(data_dir);
463469
}
464470

465471
if let Some(url) = self.l1_provider {
@@ -817,16 +823,16 @@ mod tests {
817823
}
818824

819825
#[test]
820-
fn can_launch_katana_with_db_dir() {
826+
fn can_launch_katana_with_data_dir() {
821827
let temp_dir = tempfile::tempdir().expect("failed to create temp dir");
822-
let db_path = temp_dir.path().join("test-db");
823-
assert!(!db_path.exists());
828+
let data_path = temp_dir.path().join("test-data");
829+
assert!(!data_path.exists());
824830

825-
let _katana = Katana::new().db_dir(db_path.clone()).spawn();
831+
let _katana = Katana::new().data_dir(data_path.clone()).spawn();
826832

827-
// Check that the db directory is created
828-
assert!(db_path.exists());
829-
assert!(db_path.is_dir());
833+
// Check that the data directory is created
834+
assert!(data_path.exists());
835+
assert!(data_path.is_dir());
830836
}
831837

832838
#[test]

0 commit comments

Comments
 (0)