Skip to content

Commit e66ecf9

Browse files
committed
Switched to clap derive.
1 parent d550766 commit e66ecf9

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ license = "GPL-3"
66
readme = "README.md"
77
repository = "https://github.com/RillingDev/musql"
88
description = """
9-
Music tags to SQL conversion
9+
Music tags to SQL conversion.
1010
"""
1111
edition = "2021"
1212

1313
[dependencies]
1414
log = "0.4.22"
1515
env_logger = "0.11.5"
16-
clap = "4.5.20"
16+
clap = { version = "4.5.20", features = ["derive"] }
1717
anyhow = "1.0.92"
1818
symphonia = { version = "0.5.4", features = ["all"] }
1919
rusqlite = { version = "0.32.0", features = ["bundled"] }

src/main.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use anyhow::Result;
4-
use clap::{Arg, ArgAction, Command};
4+
use clap::Parser;
55
use log::{debug, info, warn, LevelFilter};
66
use rusqlite::Connection;
77
use walkdir::WalkDir;
@@ -10,31 +10,33 @@ mod sql;
1010
mod tag;
1111
mod tag_key;
1212

13-
fn main() -> Result<()> {
14-
let matches = Command::new("musql")
15-
.arg(
16-
Arg::new("base-path")
17-
.required(true)
18-
.action(ArgAction::Set)
19-
.help("File path to scan. If a directory is specified, all contents will be scanned recursively."),
20-
)
21-
.arg(
22-
Arg::new("database-path")
23-
.long("database-path")
24-
.short('o')
25-
.required(false)
26-
.default_value("./musql.db3")
27-
.action(ArgAction::Set)
28-
.help("Path for the SQLite database that will be written to. It will be created if it does not exist."),
29-
)
30-
.get_matches();
13+
#[derive(Parser, Debug)]
14+
#[command(version, about, long_about = None)]
15+
struct Args {
16+
/// Name of the person to greet
17+
#[arg(
18+
required = true,
19+
help = "File path to scan. If a directory is specified, all contents will be scanned recursively."
20+
)]
21+
base_path: String,
22+
23+
/// Number of times to greet
24+
#[arg(
25+
short = 'o',
26+
long,
27+
required = false,
28+
default_value = "./musql.db3",
29+
help = "Path for the SQLite database that will be written to. It will be created if it does not exist."
30+
)]
31+
database_path: String,
32+
}
3133

34+
fn main() -> Result<()> {
3235
env_logger::builder().filter_level(LevelFilter::Info).init();
3336

34-
musql(
35-
matches.get_one::<String>("base-path").unwrap(),
36-
matches.get_one::<String>("database-path").unwrap(),
37-
)
37+
let args = Args::parse();
38+
39+
musql(&args.base_path, &args.database_path)
3840
}
3941

4042
fn musql(base_path: &str, database_path: &str) -> Result<()> {

0 commit comments

Comments
 (0)