Separate dependencies (#50)

Closes #39

Reviewed-on: https://git.wojciechkozlowski.eu/wojtek/musichoard/pulls/50
This commit is contained in:
Wojciech Kozlowski 2023-04-27 20:09:45 +02:00
parent ad18c7e384
commit e31b44d31d
6 changed files with 85 additions and 64 deletions

View File

@ -6,16 +6,29 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
crossterm = "0.26.1"
openssh = { version = "0.9.9", features = ["native-mux"], default-features = false }
crossterm = { version = "0.26.1", optional = true}
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_json = "1.0.95"
structopt = "0.3.26"
ratatui = "0.20.1"
tokio = { version = "1.27.0", features = ["rt"] }
serde_json = { version = "1.0.95", optional = true}
structopt = { version = "0.3.26", optional = true}
tokio = { version = "1.27.0", features = ["rt"], optional = true}
uuid = { version = "1.3.0", features = ["serde"] }
[dev-dependencies]
mockall = "0.11.4"
once_cell = "1.17.1"
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

View File

@ -17,7 +17,7 @@ env CARGO_TARGET_DIR=codecov \
env RUSTFLAGS="-C instrument-coverage" \
LLVM_PROFILE_FILE="codecov/debug/profraw/musichoard-%p-%m.profraw" \
CARGO_TARGET_DIR=codecov \
cargo test
cargo test --all-features
grcov codecov/debug/profraw \
--binary-path ./codecov/debug/ \
--output-types html \

View File

@ -7,6 +7,7 @@ use serde::{de::DeserializeOwned, Serialize};
#[cfg(test)]
use mockall::automock;
#[cfg(feature = "database-json")]
pub mod json;
/// Error type for database calls.

View File

@ -8,9 +8,6 @@ use std::{
str,
};
use openssh::{KnownHosts, Session};
use tokio::runtime::{self, Runtime};
use super::{BeetsLibraryExecutor, Error};
const BEET_DEFAULT: &str = "beet";
@ -77,6 +74,14 @@ impl BeetsLibraryExecutor for BeetsLibraryProcessExecutor {
impl BeetsLibraryExecutorPrivate for BeetsLibraryProcessExecutor {}
// GRCOV_EXCL_START
#[cfg(feature = "library-ssh")]
pub mod ssh {
use openssh::{KnownHosts, Session};
use tokio::runtime::{self, Runtime};
use super::*;
/// Beets library executor that executes beets commands over SSH.
pub struct BeetsLibrarySshExecutor {
rt: Runtime,
@ -92,15 +97,15 @@ impl From<openssh::Error> for Error {
}
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
/// 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
/// 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()
@ -137,4 +142,5 @@ impl BeetsLibraryExecutor for BeetsLibrarySshExecutor {
}
impl BeetsLibraryExecutorPrivate for BeetsLibrarySshExecutor {}
}
// GRCOV_EXCL_STOP

View File

@ -12,7 +12,7 @@ use musichoard::{
},
library::{
beets::{
executor::{BeetsLibraryProcessExecutor, BeetsLibrarySshExecutor},
executor::{ssh::BeetsLibrarySshExecutor, BeetsLibraryProcessExecutor},
BeetsLibrary,
},
Library,

View File

@ -1 +1,2 @@
#[cfg(feature = "database-json")]
mod json;