Split dependencies into features
This commit is contained in:
parent
ad18c7e384
commit
7db5e39910
25
Cargo.toml
25
Cargo.toml
@ -6,16 +6,29 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = "0.26.1"
|
crossterm = { version = "0.26.1", optional = true}
|
||||||
openssh = { version = "0.9.9", features = ["native-mux"], default-features = false }
|
openssh = { version = "0.9.9", features = ["native-mux"], default-features = false, optional = true}
|
||||||
|
ratatui = { version = "0.20.1", optional = true}
|
||||||
serde = { version = "1.0.159", features = ["derive"] }
|
serde = { version = "1.0.159", features = ["derive"] }
|
||||||
serde_json = "1.0.95"
|
serde_json = { version = "1.0.95", optional = true}
|
||||||
structopt = "0.3.26"
|
structopt = { version = "0.3.26", optional = true}
|
||||||
ratatui = "0.20.1"
|
tokio = { version = "1.27.0", features = ["rt"], optional = true}
|
||||||
tokio = { version = "1.27.0", features = ["rt"] }
|
|
||||||
uuid = { version = "1.3.0", features = ["serde"] }
|
uuid = { version = "1.3.0", features = ["serde"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
mockall = "0.11.4"
|
mockall = "0.11.4"
|
||||||
once_cell = "1.17.1"
|
once_cell = "1.17.1"
|
||||||
tempfile = "3.5.0"
|
tempfile = "3.5.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
bin = ["structopt"]
|
||||||
|
database-json = ["serde_json"]
|
||||||
|
library-ssh = ["openssh", "tokio"]
|
||||||
|
tui = ["crossterm", "ratatui"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "musichoard"
|
||||||
|
required-features = ["bin", "database-json", "library-ssh", "tui"]
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
@ -17,7 +17,7 @@ env CARGO_TARGET_DIR=codecov \
|
|||||||
env RUSTFLAGS="-C instrument-coverage" \
|
env RUSTFLAGS="-C instrument-coverage" \
|
||||||
LLVM_PROFILE_FILE="codecov/debug/profraw/musichoard-%p-%m.profraw" \
|
LLVM_PROFILE_FILE="codecov/debug/profraw/musichoard-%p-%m.profraw" \
|
||||||
CARGO_TARGET_DIR=codecov \
|
CARGO_TARGET_DIR=codecov \
|
||||||
cargo test
|
cargo test --all-features
|
||||||
grcov codecov/debug/profraw \
|
grcov codecov/debug/profraw \
|
||||||
--binary-path ./codecov/debug/ \
|
--binary-path ./codecov/debug/ \
|
||||||
--output-types html \
|
--output-types html \
|
||||||
|
@ -7,6 +7,7 @@ use serde::{de::DeserializeOwned, Serialize};
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use mockall::automock;
|
use mockall::automock;
|
||||||
|
|
||||||
|
#[cfg(feature = "database-json")]
|
||||||
pub mod json;
|
pub mod json;
|
||||||
|
|
||||||
/// Error type for database calls.
|
/// Error type for database calls.
|
||||||
|
@ -8,9 +8,6 @@ use std::{
|
|||||||
str,
|
str,
|
||||||
};
|
};
|
||||||
|
|
||||||
use openssh::{KnownHosts, Session};
|
|
||||||
use tokio::runtime::{self, Runtime};
|
|
||||||
|
|
||||||
use super::{BeetsLibraryExecutor, Error};
|
use super::{BeetsLibraryExecutor, Error};
|
||||||
|
|
||||||
const BEET_DEFAULT: &str = "beet";
|
const BEET_DEFAULT: &str = "beet";
|
||||||
@ -77,64 +74,73 @@ impl BeetsLibraryExecutor for BeetsLibraryProcessExecutor {
|
|||||||
impl BeetsLibraryExecutorPrivate for BeetsLibraryProcessExecutor {}
|
impl BeetsLibraryExecutorPrivate for BeetsLibraryProcessExecutor {}
|
||||||
|
|
||||||
// GRCOV_EXCL_START
|
// GRCOV_EXCL_START
|
||||||
/// Beets library executor that executes beets commands over SSH.
|
#[cfg(feature = "library-ssh")]
|
||||||
pub struct BeetsLibrarySshExecutor {
|
pub mod ssh {
|
||||||
rt: Runtime,
|
|
||||||
session: Session,
|
|
||||||
bin: String,
|
|
||||||
config: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<openssh::Error> for Error {
|
use openssh::{KnownHosts, Session};
|
||||||
fn from(err: openssh::Error) -> Error {
|
use tokio::runtime::{self, Runtime};
|
||||||
Error::Executor(err.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BeetsLibrarySshExecutor {
|
use super::*;
|
||||||
/// Create a new [`BeetsLibrarySshExecutor`] that uses the default beets executable over an SSH
|
|
||||||
/// connection. This call will attempt to establish the connection and will fail if the
|
/// Beets library executor that executes beets commands over SSH.
|
||||||
/// connection fails.
|
pub struct BeetsLibrarySshExecutor {
|
||||||
pub fn new<H: AsRef<str>>(host: H) -> Result<Self, Error> {
|
rt: Runtime,
|
||||||
Self::bin(host, BEET_DEFAULT)
|
session: Session,
|
||||||
|
bin: String,
|
||||||
|
config: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new [`BeetsLibrarySshExecutor`] that uses the provided beets executable over an SSH
|
impl From<openssh::Error> for Error {
|
||||||
/// connection. This call will attempt to establish the connection and will fail if the
|
fn from(err: openssh::Error) -> Error {
|
||||||
/// connection fails.
|
Error::Executor(err.to_string())
|
||||||
pub fn bin<H: AsRef<str>, S: Into<String>>(host: H, bin: S) -> Result<Self, Error> {
|
|
||||||
let rt = runtime::Builder::new_current_thread()
|
|
||||||
.enable_all()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
let session = rt.block_on(Session::connect_mux(host, KnownHosts::Strict))?;
|
|
||||||
Ok(BeetsLibrarySshExecutor {
|
|
||||||
rt,
|
|
||||||
session,
|
|
||||||
bin: bin.into(),
|
|
||||||
config: None,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update the configuration file passed to the beets executable.
|
|
||||||
pub fn config<P: Into<String>>(mut self, path: Option<P>) -> Self {
|
|
||||||
self.config = path.map(|p| p.into());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BeetsLibraryExecutor for BeetsLibrarySshExecutor {
|
|
||||||
fn exec<S: AsRef<str> + 'static>(&mut self, arguments: &[S]) -> Result<Vec<String>, Error> {
|
|
||||||
let mut cmd = self.session.command(&self.bin);
|
|
||||||
if let Some(ref path) = self.config {
|
|
||||||
cmd.arg("--config");
|
|
||||||
cmd.arg(path);
|
|
||||||
}
|
}
|
||||||
cmd.args(arguments.iter().map(|s| s.as_ref()));
|
|
||||||
let output = self.rt.block_on(cmd.output())?;
|
|
||||||
Self::output(output)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl BeetsLibraryExecutorPrivate for BeetsLibrarySshExecutor {}
|
impl BeetsLibrarySshExecutor {
|
||||||
|
/// Create a new [`BeetsLibrarySshExecutor`] that uses the default beets executable over an
|
||||||
|
/// SSH connection. This call will attempt to establish the connection and will fail if the
|
||||||
|
/// connection fails.
|
||||||
|
pub fn new<H: AsRef<str>>(host: H) -> Result<Self, Error> {
|
||||||
|
Self::bin(host, BEET_DEFAULT)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a new [`BeetsLibrarySshExecutor`] that uses the provided beets executable over an
|
||||||
|
/// SSH connection. This call will attempt to establish the connection and will fail if the
|
||||||
|
/// connection fails.
|
||||||
|
pub fn bin<H: AsRef<str>, S: Into<String>>(host: H, bin: S) -> Result<Self, Error> {
|
||||||
|
let rt = runtime::Builder::new_current_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
let session = rt.block_on(Session::connect_mux(host, KnownHosts::Strict))?;
|
||||||
|
Ok(BeetsLibrarySshExecutor {
|
||||||
|
rt,
|
||||||
|
session,
|
||||||
|
bin: bin.into(),
|
||||||
|
config: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the configuration file passed to the beets executable.
|
||||||
|
pub fn config<P: Into<String>>(mut self, path: Option<P>) -> Self {
|
||||||
|
self.config = path.map(|p| p.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BeetsLibraryExecutor for BeetsLibrarySshExecutor {
|
||||||
|
fn exec<S: AsRef<str> + 'static>(&mut self, arguments: &[S]) -> Result<Vec<String>, Error> {
|
||||||
|
let mut cmd = self.session.command(&self.bin);
|
||||||
|
if let Some(ref path) = self.config {
|
||||||
|
cmd.arg("--config");
|
||||||
|
cmd.arg(path);
|
||||||
|
}
|
||||||
|
cmd.args(arguments.iter().map(|s| s.as_ref()));
|
||||||
|
let output = self.rt.block_on(cmd.output())?;
|
||||||
|
Self::output(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BeetsLibraryExecutorPrivate for BeetsLibrarySshExecutor {}
|
||||||
|
}
|
||||||
// GRCOV_EXCL_STOP
|
// GRCOV_EXCL_STOP
|
||||||
|
@ -12,7 +12,7 @@ use musichoard::{
|
|||||||
},
|
},
|
||||||
library::{
|
library::{
|
||||||
beets::{
|
beets::{
|
||||||
executor::{BeetsLibraryProcessExecutor, BeetsLibrarySshExecutor},
|
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
|
||||||
BeetsLibrary,
|
BeetsLibrary,
|
||||||
},
|
},
|
||||||
Library,
|
Library,
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
#[cfg(feature = "database-json")]
|
||||||
mod json;
|
mod json;
|
||||||
|
Loading…
Reference in New Issue
Block a user