From 2dfd4aef4fbfb3ccbca7acd607cc27146f27046d Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Fri, 9 Dec 2022 23:43:36 -0800 Subject: [PATCH] basic flags and help docs --- Cargo.toml | 1 + src/main.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8251974..c241041 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ regex = "1.6.0" serde = { version = "1.0.143", features = ["derive"] } serde_json = "1.0.83" rusqlite = {version="0.28.0", features=["bundled"]} +scan_dir = "0.3.3" diff --git a/src/main.rs b/src/main.rs index b8f262f..518c21e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,66 @@ use clap::Parser; +use dirs_next; +use scan_dir::ScanDir; #[derive(Parser, Debug)] #[command(author, version, about, long_about=None)] struct Cli { + /// Set the root of your music library (defaults to user music dir) + #[arg(short, long)] + root_directory: Option, + + /// Specify a specific configuration file #[arg(short, long)] configuration_file: Option, + + /// Specify a specific database file + #[arg(short, long)] + database_file: Option, + + /// Start the server without a front end + #[arg(long)] + no_webserver: bool, + + /// Run the database in memory alone + #[arg(long)] + no_save: bool, + + /// Delete an existing database file (wherever it looks on startup) + #[arg(long)] + reset_database: bool, } fn main() { let cli = Cli::parse(); + // settings = confy settings + let music_dir: String; + if cli.root_directory.is_some() { + music_dir = cli.root_directory.clone().unwrap(); + println!( + "Music directory is: {}", + cli.root_directory.clone().unwrap() + ); + } else { + music_dir = String::from(dirs_next::audio_dir().unwrap().to_str().unwrap()); + println!("Music directory is: {:?}", dirs_next::audio_dir()); + } + + // ScanDir::dirs() + // and + // ScanDir::files() + //iter.filter(|&(_, ref name)| name.ends_with(".rs")) + // .map(|(ref entry, _)| entry.path()) + // .collect() + + let files = ScanDir::dirs() + .read(music_dir, |iter| { + for (entry, name) in iter { + println!("File {:?} has full path {:?}", name, entry.path()); + } + }) + .unwrap(); + println!("Hello, world!"); println!("{:?}", cli); }