diff options
author | metamuffin <metamuffin@disroot.org> | 2024-04-16 18:15:47 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-04-16 18:15:47 +0200 |
commit | ddf52f02d66abfee17a4105503220a9a34064f29 (patch) | |
tree | bb01d20ef9daea32730b98af8b159e87eea15704 /tool | |
parent | 783198703569dd1d1c17f2b3a40a62f20a6f8a44 (diff) | |
download | jellything-ddf52f02d66abfee17a4105503220a9a34064f29.tar jellything-ddf52f02d66abfee17a4105503220a9a34064f29.tar.bz2 jellything-ddf52f02d66abfee17a4105503220a9a34064f29.tar.zst |
jellytool completion generator
Diffstat (limited to 'tool')
-rw-r--r-- | tool/Cargo.toml | 3 | ||||
-rw-r--r-- | tool/src/add.rs | 13 | ||||
-rw-r--r-- | tool/src/bin/generate_completions.rs | 18 | ||||
-rw-r--r-- | tool/src/cli.rs | 39 | ||||
-rw-r--r-- | tool/src/lib.rs | 4 | ||||
-rw-r--r-- | tool/src/main.rs | 50 | ||||
-rw-r--r-- | tool/src/migrate.rs | 4 |
7 files changed, 77 insertions, 54 deletions
diff --git a/tool/Cargo.toml b/tool/Cargo.toml index 98cec15..ba74ee9 100644 --- a/tool/Cargo.toml +++ b/tool/Cargo.toml @@ -12,10 +12,11 @@ jellyclient = { path = "../client" } log = { workspace = true } env_logger = "0.11.3" anyhow = "1.0.82" -clap = { version = "4.5.4", features = ["derive"] } reqwest = { workspace = true } indicatif = "0.17.8" tokio = { workspace = true } +clap = { version = "4.5.4", features = ["derive"] } +clap_complete = "4.5.2" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" diff --git a/tool/src/add.rs b/tool/src/add.rs index 23924cb..dfec40d 100644 --- a/tool/src/add.rs +++ b/tool/src/add.rs @@ -1,18 +1,17 @@ -use std::{ - fmt::Display, - path::{Path, PathBuf}, -}; - -use crate::Action; +use crate::cli::Action; use anyhow::{anyhow, bail, Context}; use dialoguer::{theme::ColorfulTheme, Confirm, FuzzySelect, Input, MultiSelect}; use jellybase::{CONF, SECRETS}; use jellycommon::{ImportOptions, ImportSource, TraktKind}; use jellyimport::trakt::Trakt; use log::warn; +use std::{ + fmt::Display, + path::{Path, PathBuf}, +}; use tokio::{fs::File, io::AsyncWriteExt}; -pub(crate) async fn add(action: Action) -> anyhow::Result<()> { +pub async fn add(action: Action) -> anyhow::Result<()> { match action { Action::Add { id, diff --git a/tool/src/bin/generate_completions.rs b/tool/src/bin/generate_completions.rs new file mode 100644 index 0000000..9f0917f --- /dev/null +++ b/tool/src/bin/generate_completions.rs @@ -0,0 +1,18 @@ +use clap::{CommandFactory, Parser, ValueEnum}; +use clap_complete::{generate_to, Shell}; +use jellytool::cli; +use std::{fs::create_dir_all, path::PathBuf}; + +#[derive(Parser)] +struct Args { + out_dir: PathBuf, +} + +fn main() -> anyhow::Result<()> { + let args = Args::parse(); + create_dir_all(&args.out_dir)?; + for &shell in Shell::value_variants() { + generate_to(shell, &mut cli::Args::command(), "jellytool", &args.out_dir)?; + } + Ok(()) +} diff --git a/tool/src/cli.rs b/tool/src/cli.rs new file mode 100644 index 0000000..d13d575 --- /dev/null +++ b/tool/src/cli.rs @@ -0,0 +1,39 @@ +use clap::{arg, Parser, Subcommand, ValueEnum}; +use std::path::PathBuf; + +#[derive(Parser)] +pub struct Args { + #[clap(subcommand)] + pub action: Action, +} + +#[derive(Subcommand)] +pub enum Action { + Add { + #[arg(short, long)] + id: Option<String>, + #[arg(short, long)] + media: Option<PathBuf>, + #[arg(short, long)] + library_path: Option<PathBuf>, + }, + Migrate { + database: PathBuf, + mode: MigrateMode, + save_location: PathBuf, + }, + Reimport { + /// Custom hostname, the config's is used by default + #[arg(long)] + hostname: Option<String>, + /// Disable TLS. Dont use this. + #[arg(long)] + no_tls: bool, + }, +} + +#[derive(Debug, Clone, Copy, PartialEq, ValueEnum)] +pub enum MigrateMode { + Import, + Export, +} diff --git a/tool/src/lib.rs b/tool/src/lib.rs new file mode 100644 index 0000000..71c7346 --- /dev/null +++ b/tool/src/lib.rs @@ -0,0 +1,4 @@ + +pub mod add; +pub mod cli; +pub mod migrate;
\ No newline at end of file diff --git a/tool/src/main.rs b/tool/src/main.rs index d2518e8..a896fa2 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -4,55 +4,17 @@ Copyright (C) 2024 metamuffin <metamuffin.org> */ -pub mod add; -pub mod migrate; - -use add::add; use anyhow::anyhow; -use clap::{Parser, Subcommand, ValueEnum}; +use clap::Parser; use jellybase::{CONF, SECRETS}; use jellyclient::Instance; use jellycommon::user::CreateSessionParams; +use jellytool::{ + add::add, + cli::{Action, Args}, + migrate::migrate, +}; use log::info; -use migrate::migrate; -use std::{fmt::Debug, path::PathBuf}; - -#[derive(Parser)] -struct Args { - #[clap(subcommand)] - action: Action, -} - -#[derive(Subcommand)] -enum Action { - Add { - #[arg(short, long)] - id: Option<String>, - #[arg(short, long)] - media: Option<PathBuf>, - #[arg(short, long)] - library_path: Option<PathBuf>, - }, - Migrate { - database: PathBuf, - mode: MigrateMode, - save_location: PathBuf, - }, - Reimport { - /// Custom hostname, the config's is used by default - #[arg(long)] - hostname: Option<String>, - /// Disable TLS. Dont use this. - #[arg(long)] - no_tls: bool, - }, -} - -#[derive(Debug, Clone, Copy, PartialEq, ValueEnum)] -enum MigrateMode { - Import, - Export, -} fn main() -> anyhow::Result<()> { env_logger::builder() diff --git a/tool/src/migrate.rs b/tool/src/migrate.rs index cb7647e..0412430 100644 --- a/tool/src/migrate.rs +++ b/tool/src/migrate.rs @@ -3,7 +3,7 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2024 metamuffin <metamuffin.org> */ -use crate::{Action, MigrateMode}; +use crate::cli::{Action, MigrateMode}; use anyhow::{bail, Context}; use indicatif::ProgressIterator; use jellybase::database::redb::ReadableTableMetadata; @@ -90,7 +90,7 @@ use std::{ // } // } -pub(crate) fn migrate(action: Action) -> anyhow::Result<()> { +pub fn migrate(action: Action) -> anyhow::Result<()> { match action { Action::Migrate { mode, |