mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Extract pict-rs as library
This commit is contained in:
parent
0da6159cf1
commit
2c1a37fb62
3 changed files with 1393 additions and 1313 deletions
|
@ -1,4 +1,5 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
mod commandline;
|
mod commandline;
|
||||||
mod defaults;
|
mod defaults;
|
||||||
|
@ -15,6 +16,34 @@ pub(crate) use primitives::{
|
||||||
AudioCodec, Filesystem, ImageFormat, LogFormat, ObjectStorage, Store, VideoCodec,
|
AudioCodec, Filesystem, ImageFormat, LogFormat, ObjectStorage, Store, VideoCodec,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub(crate) fn configure_without_clap<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||||
|
config_file: Option<P>,
|
||||||
|
save_to: Option<Q>,
|
||||||
|
) -> color_eyre::Result<(Configuration, Operation)> {
|
||||||
|
let config = Config::builder().add_source(config::Config::try_from(&Defaults::default())?);
|
||||||
|
|
||||||
|
let config = if let Some(config_file) = config_file {
|
||||||
|
config.add_source(config::File::from(config_file.as_ref()))
|
||||||
|
} else {
|
||||||
|
config
|
||||||
|
};
|
||||||
|
|
||||||
|
let built = config
|
||||||
|
.add_source(config::Environment::with_prefix("PICTRS").separator("__"))
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let operation = Operation::Run;
|
||||||
|
|
||||||
|
let config: Configuration = built.try_deserialize()?;
|
||||||
|
|
||||||
|
if let Some(save_to) = save_to {
|
||||||
|
let output = toml::to_string_pretty(&config)?;
|
||||||
|
std::fs::write(save_to, output)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok((config, operation))
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn configure() -> color_eyre::Result<(Configuration, Operation)> {
|
pub(crate) fn configure() -> color_eyre::Result<(Configuration, Operation)> {
|
||||||
let Output {
|
let Output {
|
||||||
config_format,
|
config_format,
|
||||||
|
|
1362
src/lib.rs
Normal file
1362
src/lib.rs
Normal file
File diff suppressed because it is too large
Load diff
1315
src/main.rs
1315
src/main.rs
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue