mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Wrap options for yabridgectl sync/set in a struct
To prevent having to pass a bunch of confusing boolean values or an entire ArgMatch object.
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
//! Handlers for the subcommands, just to keep `main.rs` clean.
|
//! Handlers for the subcommands, just to keep `main.rs` clean.
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use clap::ArgMatches;
|
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::os::unix::fs::symlink;
|
use std::os::unix::fs::symlink;
|
||||||
@@ -123,32 +122,37 @@ pub fn show_status(config: &Config) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Options passed to `yabridgectl set`, see `main()` for the definitions of these options.
|
||||||
|
pub struct SetOptions<'a> {
|
||||||
|
pub method: Option<&'a str>,
|
||||||
|
pub path: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
/// Change configuration settings. The actual options are defined in the clap [app](clap::App).
|
/// Change configuration settings. The actual options are defined in the clap [app](clap::App).
|
||||||
pub fn set_settings(config: &mut Config, options: &ArgMatches) -> Result<()> {
|
pub fn set_settings(config: &mut Config, options: &SetOptions) -> Result<()> {
|
||||||
match options.value_of("method") {
|
match options.method {
|
||||||
Some("copy") => config.method = InstallationMethod::Copy,
|
Some("copy") => config.method = InstallationMethod::Copy,
|
||||||
Some("symlink") => config.method = InstallationMethod::Symlink,
|
Some("symlink") => config.method = InstallationMethod::Symlink,
|
||||||
Some(s) => unimplemented!("Unexpected installation method '{}'", s),
|
Some(s) => unimplemented!("Unexpected installation method '{}'", s),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match options.value_of_t("path") {
|
if let Some(path) = &options.path {
|
||||||
Ok(path) => config.yabridge_home = Some(path),
|
config.yabridge_home = Some(path.clone());
|
||||||
Err(clap::Error {
|
|
||||||
kind: clap::ErrorKind::ArgumentNotFound,
|
|
||||||
..
|
|
||||||
}) => (),
|
|
||||||
// I don't think we can get any parsing errors here since we already validated that the
|
|
||||||
// argument has to be a valid path, but you never know
|
|
||||||
Err(err) => err.exit(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config.write()
|
config.write()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Options passed to `yabridgectl sync`, see `main()` for the definitions of these options.
|
||||||
|
pub struct SyncOptions {
|
||||||
|
pub prune: bool,
|
||||||
|
pub verbose: bool,
|
||||||
|
}
|
||||||
|
|
||||||
/// Set up yabridge for all Windows VST2 plugins in the plugin directories. Will also remove orphan
|
/// Set up yabridge for all Windows VST2 plugins in the plugin directories. Will also remove orphan
|
||||||
/// `.so` files if the prune option is set.
|
/// `.so` files if the prune option is set.
|
||||||
pub fn do_sync(config: &Config, prune: bool, verbose: bool) -> Result<()> {
|
pub fn do_sync(config: &Config, options: &SyncOptions) -> Result<()> {
|
||||||
let libyabridge_path = config.libyabridge()?;
|
let libyabridge_path = config.libyabridge()?;
|
||||||
println!("Using '{}'\n", libyabridge_path.display());
|
println!("Using '{}'\n", libyabridge_path.display());
|
||||||
|
|
||||||
@@ -165,7 +169,7 @@ pub fn do_sync(config: &Config, prune: bool, verbose: bool) -> Result<()> {
|
|||||||
orphan_so_files.extend(search_results.orphans().into_iter().cloned());
|
orphan_so_files.extend(search_results.orphans().into_iter().cloned());
|
||||||
skipped_dll_files.extend(search_results.skipped_files);
|
skipped_dll_files.extend(search_results.skipped_files);
|
||||||
|
|
||||||
if verbose {
|
if options.verbose {
|
||||||
println!("{}:", path.display());
|
println!("{}:", path.display());
|
||||||
}
|
}
|
||||||
for plugin in search_results.vst2_files {
|
for plugin in search_results.vst2_files {
|
||||||
@@ -198,18 +202,18 @@ pub fn do_sync(config: &Config, prune: bool, verbose: bool) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if verbose {
|
if options.verbose {
|
||||||
println!(" {}", plugin.display());
|
println!(" {}", plugin.display());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if verbose {
|
if options.verbose {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll print the skipped files all at once to prevetn clutter
|
// We'll print the skipped files all at once to prevetn clutter
|
||||||
let num_skipped_files = skipped_dll_files.len();
|
let num_skipped_files = skipped_dll_files.len();
|
||||||
if verbose && !skipped_dll_files.is_empty() {
|
if options.verbose && !skipped_dll_files.is_empty() {
|
||||||
println!("Skipped files:");
|
println!("Skipped files:");
|
||||||
for path in skipped_dll_files {
|
for path in skipped_dll_files {
|
||||||
println!("- {}", path.display());
|
println!("- {}", path.display());
|
||||||
@@ -220,7 +224,7 @@ pub fn do_sync(config: &Config, prune: bool, verbose: bool) -> Result<()> {
|
|||||||
// Always warn about leftover files sicne those might cause warnings or errors when a VST host
|
// Always warn about leftover files sicne those might cause warnings or errors when a VST host
|
||||||
// tries to load them
|
// tries to load them
|
||||||
if !orphan_so_files.is_empty() {
|
if !orphan_so_files.is_empty() {
|
||||||
if prune {
|
if options.prune {
|
||||||
println!("Removing {} leftover .so files:", orphan_so_files.len());
|
println!("Removing {} leftover .so files:", orphan_so_files.len());
|
||||||
} else {
|
} else {
|
||||||
println!(
|
println!(
|
||||||
@@ -233,7 +237,7 @@ pub fn do_sync(config: &Config, prune: bool, verbose: bool) -> Result<()> {
|
|||||||
let path = file.path();
|
let path = file.path();
|
||||||
|
|
||||||
println!("- {}", path.display());
|
println!("- {}", path.display());
|
||||||
if prune {
|
if options.prune {
|
||||||
fs::remove_file(path)
|
fs::remove_file(path)
|
||||||
.with_context(|| format!("Could not remove '{}'", path.display()))?;
|
.with_context(|| format!("Could not remove '{}'", path.display()))?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,11 +124,21 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
("list", _) => actions::list_directories(&config),
|
("list", _) => actions::list_directories(&config),
|
||||||
("status", _) => actions::show_status(&config),
|
("status", _) => actions::show_status(&config),
|
||||||
("set", Some(options)) => actions::set_settings(&mut config, options),
|
("set", Some(options)) => actions::set_settings(
|
||||||
|
&mut config,
|
||||||
|
&actions::SetOptions {
|
||||||
|
method: options.value_of("method"),
|
||||||
|
// We've already verified that the path is valid, so we should only be getting
|
||||||
|
// errors for missing arguments
|
||||||
|
path: options.value_of_t("path").ok(),
|
||||||
|
},
|
||||||
|
),
|
||||||
("sync", Some(options)) => actions::do_sync(
|
("sync", Some(options)) => actions::do_sync(
|
||||||
&config,
|
&config,
|
||||||
options.is_present("prune"),
|
&actions::SyncOptions {
|
||||||
options.is_present("verbose"),
|
prune: options.is_present("prune"),
|
||||||
|
verbose: options.is_present("verbose"),
|
||||||
|
},
|
||||||
),
|
),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user