aboutsummaryrefslogtreecommitdiff
path: root/tool/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-22 11:59:47 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-22 11:59:47 +0100
commit18a791635283482d4e48cb7ef00df8f908ff22ac (patch)
tree1989c06ffb86c010807be29f986f26cbf9a0760b /tool/src
parent28011dfa78aacfdb3416bd3b7676eec25542a534 (diff)
downloadjellything-18a791635283482d4e48cb7ef00df8f908ff22ac.tar
jellything-18a791635283482d4e48cb7ef00df8f908ff22ac.tar.bz2
jellything-18a791635283482d4e48cb7ef00df8f908ff22ac.tar.zst
tool: cleanup
Diffstat (limited to 'tool/src')
-rw-r--r--tool/src/main.rs87
1 files changed, 25 insertions, 62 deletions
diff --git a/tool/src/main.rs b/tool/src/main.rs
index 6384822..7b58125 100644
--- a/tool/src/main.rs
+++ b/tool/src/main.rs
@@ -7,6 +7,7 @@
pub mod migrate;
+use anyhow::anyhow;
use base64::Engine;
use clap::{Parser, Subcommand, ValueEnum};
use jellyclient::{Instance, LoginDetails};
@@ -18,8 +19,9 @@ use std::{fmt::Debug, fs::File, io::Write, path::PathBuf};
#[derive(Parser)]
struct Args {
- #[arg(short = 'N', long)]
- dry: bool,
+ /// Path to global jellything config
+ #[arg(short = 'C', long)]
+ config: Option<PathBuf>,
#[clap(subcommand)]
action: Action,
}
@@ -35,55 +37,12 @@ enum Action {
#[arg(short, long)]
hostname: String,
},
- // /// Imports a movie, video or series given media and metadata sources
- // New {
- // /// Relative path to the node's parent(!).
- // path: PathBuf,
- // /// Search the node by title on TMDB
- // #[arg(short = 't', long)]
- // tmdb_search: Option<String>,
- // /// Search the node by id on TMDB
- // #[arg(short = 'T', long)]
- // tmdb_id: Option<String>,
- // #[arg(long)]
- // /// Prefix the inferred id with something to avoid collisions
- // ident_prefix: Option<String>,
- // /// Copies media into the library
- // #[arg(long)]
- // copy: bool,
- // /// Moves media into the library (potentially destructive operation)
- // #[arg(long)]
- // r#move: bool,
- // /// Marks node as a video
- // #[arg(long)]
- // video: bool,
- // /// Marks node as a series
- // #[arg(short, long)]
- // series: bool,
- // /// Path to the media of the node, required for non-series
- // #[arg(short, long)]
- // input: Option<PathBuf>,
- // /// Ignore attachments (dont use them as cover)
- // #[arg(long)]
- // ignore_attachments: bool,
- // /// Ignore metadate (no title, description and tagline from input)
- // #[arg(long)]
- // ignore_metadata: bool,
- // /// Skip any action that appears to be run already.
- // #[arg(long)]
- // skip_existing: bool,
- // /// Sets the title
- // #[arg(long)]
- // title: Option<String>,
- // },
Migrate {
database: PathBuf,
mode: MigrateMode,
save_location: PathBuf,
},
Reimport {
- /// Path to global jellything config
- config: PathBuf,
/// Custom hostname, the config's is used by default
#[arg(long)]
hostname: Option<String>,
@@ -106,6 +65,16 @@ fn main() -> anyhow::Result<()> {
.init();
let args = Args::parse();
+ let config = args
+ .config
+ .or(std::env::var_os("JELLYTHING_CONFIG").map(|p| PathBuf::from(p)))
+ .map(|path| {
+ Ok::<_, anyhow::Error>(serde_yaml::from_reader::<_, GlobalConfig>(File::open(
+ path,
+ )?)?)
+ })
+ .transpose()?;
+
match args.action {
Action::Init {
base_path: path,
@@ -163,19 +132,13 @@ fn main() -> anyhow::Result<()> {
warn!("please change the admin password.");
Ok(())
}
- // a @ Action::New { .. } => import(a, args.dry),
a @ Action::Migrate { .. } => migrate(a),
- Action::Reimport {
- config,
- hostname,
- no_tls,
- } => tokio::runtime::Builder::new_multi_thread()
+ Action::Reimport { hostname, no_tls } => tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async move {
- let config = serde_yaml::from_reader::<_, GlobalConfig>(File::open(config)?)?;
-
+ let config = config.ok_or(anyhow!("this action requires the config"))?;
let inst = Instance::new(hostname.unwrap_or(config.hostname.clone()), !no_tls);
info!("login");
let session = inst
@@ -193,12 +156,12 @@ fn main() -> anyhow::Result<()> {
}
}
-fn ok_or_warn<T, E: Debug>(r: Result<T, E>) -> Option<T> {
- match r {
- Ok(t) => Some(t),
- Err(e) => {
- warn!("{e:?}");
- None
- }
- }
-}
+// fn ok_or_warn<T, E: Debug>(r: Result<T, E>) -> Option<T> {
+// match r {
+// Ok(t) => Some(t),
+// Err(e) => {
+// warn!("{e:?}");
+// None
+// }
+// }
+// }