diff --git a/tools/yabridgectl/Cargo.toml b/tools/yabridgectl/Cargo.toml index f6f2c5f0..b67b1f93 100644 --- a/tools/yabridgectl/Cargo.toml +++ b/tools/yabridgectl/Cargo.toml @@ -5,7 +5,7 @@ name = "yabridgectl" version = "1.2.1" authors = ["Robbert van der Helm "] edition = "2018" -description = "Optional command line helper to set up yabridge" +description = "Optional utility to help set up yabridge" repository = "https://github.com/robbert-vdh/yabridge" license = "GPL-3.0-or-later" diff --git a/tools/yabridgectl/src/config.rs b/tools/yabridgectl/src/config.rs index f09db536..18e061ed 100644 --- a/tools/yabridgectl/src/config.rs +++ b/tools/yabridgectl/src/config.rs @@ -75,7 +75,7 @@ impl Config { })?; Ok(toml::from_str(&toml_str) - .map_err(|err| format!("Could not parse TOML: {:#?}", err))?) + .map_err(|err| format!("Could not parse TOML: {}", err))?) } None => { let defaults = Config { diff --git a/tools/yabridgectl/src/main.rs b/tools/yabridgectl/src/main.rs index b3dc57d4..9db334a2 100644 --- a/tools/yabridgectl/src/main.rs +++ b/tools/yabridgectl/src/main.rs @@ -14,24 +14,69 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use clap::{app_from_crate, App, Arg}; +use config::Config; +use std::path::Path; + mod config; mod files; -use config::Config; +// TODO: Naming and descriptions could be made clearer fn main() { - // TODO: Remove debug - match Config::read() { - Ok(config) => { - println!("Read config:\n\n{:#?}\n", config); - println!( - "Searching for libyabridge.toml:\n\n{:?}", - config.libyabridge() - ); - } + let config = match Config::read() { + Ok(config) => config, Err(err) => { eprintln!("Error while reading config:\n\n{}", err); std::process::exit(1); } + }; + + // Used for validation in `yabridgectl rm ` + let plugin_directories: Vec<&str> = config + .plugin_dirs + .iter() + .map(|path| path.to_str().expect("Path contains invalid unicode")) + .collect(); + + let matches = app_from_crate!() + .subcommand( + App::new("add").about("Add a plugin install location").arg( + Arg::with_name("path") + .about("Path to a directory containing Windows VST plugins") + .validator(validate_path) + .takes_value(true) + .required(true), + ), + ) + .subcommand( + App::new("rm") + .about("Remove a plugin install location") + .arg( + Arg::with_name("path") + .about("Path to a directory") + .possible_values(&plugin_directories) + .takes_value(true) + .required(true), + ), + ) + .subcommand(App::new("list").about("List the plugin directories")) + .get_matches(); + + // TODO: Modify the config file using these options + unimplemented!(); +} + +/// Verify that a path exists, used for validating arguments. +fn validate_path(path: &str) -> Result<(), String> { + let path = Path::new(path); + + if path.exists() { + Ok(()) + } else { + Err(format!( + "File or directory '{}' could not be found", + path.display() + )) } }