mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-24 08:22:10 -04:00
refactor: Update argument handling and imports across CLI domains
- Refactored argument handling in the job and library domains to improve clarity and consistency. - Updated imports to use the correct input types for actions in the library and location modules. - Enhanced type annotations for better readability and maintainability in the codebase.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use clap::{Args, ValueEnum};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
use uuid::Uuid;
|
||||
|
||||
use sd_core::{
|
||||
|
||||
@@ -6,7 +6,10 @@ use clap::Subcommand;
|
||||
use crate::util::prelude::*;
|
||||
|
||||
use crate::{context::Context, util::error::CliError};
|
||||
use sd_core::ops::{indexing::action::IndexOutput, libraries::list::query::ListLibrariesQuery};
|
||||
use sd_core::{
|
||||
infra::job::types::JobId,
|
||||
ops::libraries::list::query::ListLibrariesQuery,
|
||||
};
|
||||
|
||||
use self::args::*;
|
||||
|
||||
@@ -40,13 +43,13 @@ pub async fn run(ctx: &Context, cmd: IndexCmd) -> Result<()> {
|
||||
anyhow::bail!(errors.join("; "));
|
||||
}
|
||||
|
||||
let out: IndexOutput = execute_action!(ctx, input);
|
||||
let out: JobId = execute_action!(ctx, input);
|
||||
print_output!(ctx, out, |_| {
|
||||
println!("Indexing request submitted");
|
||||
});
|
||||
}
|
||||
IndexCmd::QuickScan(args) => {
|
||||
let libs = execute_query!(ctx, ListLibrariesQuery::basic());
|
||||
let libs: Vec<sd_core::ops::libraries::list::output::LibraryInfo> = execute_query!(ctx, ListLibrariesQuery::basic());
|
||||
let library_id = match libs.len() {
|
||||
1 => libs[0].id,
|
||||
_ => {
|
||||
@@ -55,20 +58,20 @@ pub async fn run(ctx: &Context, cmd: IndexCmd) -> Result<()> {
|
||||
};
|
||||
|
||||
let input = args.to_input(library_id)?;
|
||||
let out: IndexOutput = execute_action!(ctx, input);
|
||||
let out: JobId = execute_action!(ctx, input);
|
||||
print_output!(ctx, out, |_| {
|
||||
println!("Quick scan request submitted");
|
||||
});
|
||||
}
|
||||
IndexCmd::Browse(args) => {
|
||||
let libs = execute_query!(ctx, ListLibrariesQuery::basic());
|
||||
let libs: Vec<sd_core::ops::libraries::list::output::LibraryInfo> = execute_query!(ctx, ListLibrariesQuery::basic());
|
||||
let library_id = match libs.len() {
|
||||
1 => libs[0].id,
|
||||
_ => anyhow::bail!("Specify --library for browse when multiple libraries exist"),
|
||||
};
|
||||
|
||||
let input = args.to_input(library_id)?;
|
||||
let out: IndexOutput = execute_action!(ctx, input);
|
||||
let out: JobId = execute_action!(ctx, input);
|
||||
print_output!(ctx, out, |_| {
|
||||
println!("Browse request submitted");
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct JobListArgs {
|
||||
}
|
||||
|
||||
impl JobListArgs {
|
||||
pub fn to_query(&self, library_id: Uuid) -> JobListQuery {
|
||||
pub fn to_query(&self, _library_id: Uuid) -> JobListQuery {
|
||||
JobListQuery {
|
||||
status: self.status.as_deref().and_then(|s| s.parse::<JobStatus>().ok()),
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use uuid::Uuid;
|
||||
|
||||
use sd_core::ops::libraries::{
|
||||
create::input::LibraryCreateInput,
|
||||
delete::action::LibraryDeleteInput,
|
||||
delete::input::LibraryDeleteInput,
|
||||
session::set_current::SetCurrentLibraryInput,
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::util::prelude::*;
|
||||
|
||||
use crate::context::Context;
|
||||
use sd_core::ops::libraries::{
|
||||
create::output::LibraryCreateOutput,
|
||||
create::{input::LibraryCreateInput, output::LibraryCreateOutput},
|
||||
delete::output::LibraryDeleteOutput,
|
||||
list::query::ListLibrariesQuery,
|
||||
session::set_current::SetCurrentLibraryOutput,
|
||||
@@ -30,7 +30,8 @@ pub enum LibraryCmd {
|
||||
pub async fn run(ctx: &Context, cmd: LibraryCmd) -> Result<()> {
|
||||
match cmd {
|
||||
LibraryCmd::Create(args) => {
|
||||
let out: LibraryCreateOutput = execute_action!(ctx, args.into());
|
||||
let input: LibraryCreateInput = args.into();
|
||||
let out: LibraryCreateOutput = execute_action!(ctx, input);
|
||||
print_output!(ctx, &out, |o: &LibraryCreateOutput| {
|
||||
println!(
|
||||
"Created library {} with ID {} at {}",
|
||||
@@ -39,12 +40,14 @@ pub async fn run(ctx: &Context, cmd: LibraryCmd) -> Result<()> {
|
||||
});
|
||||
}
|
||||
LibraryCmd::Switch(args) => {
|
||||
let out: SetCurrentLibraryOutput = execute_action!(ctx, args.into());
|
||||
let library_id = args.id;
|
||||
let input: sd_core::ops::libraries::session::set_current::SetCurrentLibraryInput = args.into();
|
||||
let out: SetCurrentLibraryOutput = execute_action!(ctx, input);
|
||||
print_output!(ctx, &out, |o: &SetCurrentLibraryOutput| {
|
||||
if o.success {
|
||||
println!("Switched to library {}", args.id);
|
||||
println!("Switched to library {}", library_id);
|
||||
} else {
|
||||
println!("Failed to switch to library {}", args.id);
|
||||
println!("Failed to switch to library {}", library_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -67,7 +70,8 @@ pub async fn run(ctx: &Context, cmd: LibraryCmd) -> Result<()> {
|
||||
format!("This will remove library {} from Spacedrive (data will remain). Continue?", args.library_id)
|
||||
};
|
||||
confirm_or_abort(&msg, args.yes)?;
|
||||
let out: LibraryDeleteOutput = execute_action!(ctx, args.into());
|
||||
let input: sd_core::ops::libraries::delete::input::LibraryDeleteInput = args.into();
|
||||
let out: LibraryDeleteOutput = execute_action!(ctx, input);
|
||||
print_output!(ctx, &out, |o: &LibraryDeleteOutput| {
|
||||
println!("Deleted library {}", o.library_id);
|
||||
});
|
||||
|
||||
@@ -7,8 +7,7 @@ use crate::util::prelude::*;
|
||||
|
||||
use crate::context::Context;
|
||||
use sd_core::ops::locations::{
|
||||
action::LocationAddInput,
|
||||
add::output::LocationAddOutput,
|
||||
add::{action::LocationAddInput, output::LocationAddOutput},
|
||||
list::{output::LocationsListOutput, query::LocationsListQuery},
|
||||
remove::output::LocationRemoveOutput,
|
||||
rescan::output::LocationRescanOutput,
|
||||
@@ -44,20 +43,22 @@ pub async fn run(ctx: &Context, cmd: LocationCmd) -> Result<()> {
|
||||
println!("No locations found");
|
||||
return;
|
||||
}
|
||||
for loc in o.locations {
|
||||
for loc in &o.locations {
|
||||
println!("- {} {}", loc.id, loc.path.display());
|
||||
}
|
||||
});
|
||||
}
|
||||
LocationCmd::Remove(args) => {
|
||||
confirm_or_abort(&format!("This will remove location {} from the library. Continue?", args.location_id), args.yes)?;
|
||||
let out: LocationRemoveOutput = execute_action!(ctx, args.into());
|
||||
let input: sd_core::ops::locations::remove::action::LocationRemoveInput = args.into();
|
||||
let out: LocationRemoveOutput = execute_action!(ctx, input);
|
||||
print_output!(ctx, &out, |o: &LocationRemoveOutput| {
|
||||
println!("Removed location {}", o.location_id);
|
||||
});
|
||||
}
|
||||
LocationCmd::Rescan(args) => {
|
||||
let out: LocationRescanOutput = execute_action!(ctx, args.into());
|
||||
let input: sd_core::ops::locations::rescan::action::LocationRescanInput = args.into();
|
||||
let out: LocationRescanOutput = execute_action!(ctx, input);
|
||||
print_output!(ctx, &out, |o: &LocationRescanOutput| {
|
||||
println!("Rescan requested for {}", o.location_id);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod confirm;
|
||||
pub mod error;
|
||||
pub mod macros;
|
||||
pub mod output;
|
||||
|
||||
Reference in New Issue
Block a user