mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Add subcommands for managing directories
This commit is contained in:
@@ -5,7 +5,7 @@ name = "yabridgectl"
|
||||
version = "1.2.1"
|
||||
authors = ["Robbert van der Helm <mail@robbertvanderhelm.nl>"]
|
||||
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"
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -14,24 +14,69 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
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 <path>`
|
||||
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()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user