mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Add subcommands for managing directories
This commit is contained in:
@@ -5,7 +5,7 @@ name = "yabridgectl"
|
|||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
authors = ["Robbert van der Helm <mail@robbertvanderhelm.nl>"]
|
authors = ["Robbert van der Helm <mail@robbertvanderhelm.nl>"]
|
||||||
edition = "2018"
|
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"
|
repository = "https://github.com/robbert-vdh/yabridge"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ impl Config {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(toml::from_str(&toml_str)
|
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 => {
|
None => {
|
||||||
let defaults = Config {
|
let defaults = Config {
|
||||||
|
|||||||
@@ -14,24 +14,69 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// 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 config;
|
||||||
mod files;
|
mod files;
|
||||||
|
|
||||||
use config::Config;
|
// TODO: Naming and descriptions could be made clearer
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// TODO: Remove debug
|
let config = match Config::read() {
|
||||||
match Config::read() {
|
Ok(config) => config,
|
||||||
Ok(config) => {
|
|
||||||
println!("Read config:\n\n{:#?}\n", config);
|
|
||||||
println!(
|
|
||||||
"Searching for libyabridge.toml:\n\n{:?}",
|
|
||||||
config.libyabridge()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error while reading config:\n\n{}", err);
|
eprintln!("Error while reading config:\n\n{}", err);
|
||||||
std::process::exit(1);
|
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