use std::path::PathBuf;
use clap::{Args, Subcommand};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::{
entity::{content::ArtifactContentType, state::TaskState},
schema::{
ArtifactsDeleteByFilterReq, ArtifactsDeleteByUuidsReq, ArtifactsDownloadByFilterReq,
ArtifactsDownloadByUuidsReq,
},
};
#[derive(Serialize, Debug, Deserialize, Args, derive_more::From, Clone)]
pub struct ArtifactsArgs {
#[command(subcommand)]
pub command: ArtifactsCommands,
}
#[derive(Subcommand, Serialize, Debug, Deserialize, derive_more::From, Clone)]
pub enum ArtifactsCommands {
Delete(DeleteArtifactArgs),
Upload(UploadArtifactArgs),
Download(DownloadArtifactArgs),
DownloadMany(DownloadArtifactsByFilterArgs),
DownloadList(DownloadArtifactsByListArgs),
DeleteMany(DeleteArtifactsByFilterArgs),
DeleteList(DeleteArtifactsByListArgs),
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct DeleteArtifactArgs {
pub uuid: Uuid,
#[arg(value_enum)]
pub content_type: ArtifactContentType,
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct UploadArtifactArgs {
pub local_file: PathBuf,
pub uuid: Uuid,
#[arg(value_enum)]
pub content_type: ArtifactContentType,
#[arg(long)]
pub pb: bool,
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct DownloadArtifactArgs {
pub uuid: Uuid,
#[arg(value_enum)]
pub content_type: ArtifactContentType,
#[arg(short, long = "output")]
pub output_path: Option<String>,
#[arg(long)]
pub no_download: bool,
#[arg(long)]
pub pb: bool,
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct DownloadArtifactsByFilterArgs {
#[arg(value_enum)]
pub content_type: ArtifactContentType,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub creators: Vec<String>,
#[arg(short, long)]
pub group: Option<String>,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub tags: Vec<String>,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub labels: Vec<String>,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub state: Vec<TaskState>,
#[arg(short, long)]
pub exit_status: Option<String>,
#[arg(short, long)]
pub priority: Option<String>,
#[arg(long)]
pub reporter_uuid: Option<Uuid>,
#[arg(short, long = "output")]
pub output_dir: Option<PathBuf>,
#[arg(long)]
pub no_download: bool,
#[arg(long)]
pub pb: bool,
#[arg(long, default_value_t = 1)]
pub concurrent: usize,
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct DownloadArtifactsByListArgs {
#[arg(value_enum)]
pub content_type: ArtifactContentType,
#[arg(num_args = 1..)]
pub uuids: Vec<Uuid>,
#[arg(short, long = "output")]
pub output_dir: Option<PathBuf>,
#[arg(long)]
pub no_download: bool,
#[arg(long)]
pub pb: bool,
#[arg(long, default_value_t = 1)]
pub concurrent: usize,
}
impl From<DownloadArtifactsByFilterArgs> for ArtifactsDownloadByFilterReq {
fn from(args: DownloadArtifactsByFilterArgs) -> Self {
Self {
reporter_uuid: args.reporter_uuid,
creator_usernames: if args.creators.is_empty() {
None
} else {
Some(args.creators.into_iter().collect())
},
group_name: args.group,
tags: if args.tags.is_empty() {
None
} else {
Some(args.tags.into_iter().collect())
},
labels: if args.labels.is_empty() {
None
} else {
Some(args.labels.into_iter().collect())
},
states: if args.state.is_empty() {
None
} else {
Some(args.state.into_iter().collect())
},
exit_status: args.exit_status,
priority: args.priority,
content_type: args.content_type,
}
}
}
impl From<DownloadArtifactsByListArgs> for ArtifactsDownloadByUuidsReq {
fn from(args: DownloadArtifactsByListArgs) -> Self {
Self {
uuids: args.uuids,
content_type: args.content_type,
}
}
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct DeleteArtifactsByFilterArgs {
#[arg(value_enum)]
pub content_type: ArtifactContentType,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub creators: Vec<String>,
#[arg(short, long)]
pub group: Option<String>,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub tags: Vec<String>,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub labels: Vec<String>,
#[arg(short, long, num_args = 0.., value_delimiter = ',')]
pub state: Vec<TaskState>,
#[arg(short, long)]
pub exit_status: Option<String>,
#[arg(short, long)]
pub priority: Option<String>,
#[arg(long)]
pub reporter_uuid: Option<Uuid>,
}
#[derive(Serialize, Debug, Deserialize, Args, Clone)]
pub struct DeleteArtifactsByListArgs {
#[arg(value_enum)]
pub content_type: ArtifactContentType,
#[arg(num_args = 1..)]
pub uuids: Vec<Uuid>,
}
impl From<DeleteArtifactsByFilterArgs> for ArtifactsDeleteByFilterReq {
fn from(args: DeleteArtifactsByFilterArgs) -> Self {
Self {
reporter_uuid: args.reporter_uuid,
creator_usernames: if args.creators.is_empty() {
None
} else {
Some(args.creators.into_iter().collect())
},
group_name: args.group,
tags: if args.tags.is_empty() {
None
} else {
Some(args.tags.into_iter().collect())
},
labels: if args.labels.is_empty() {
None
} else {
Some(args.labels.into_iter().collect())
},
states: if args.state.is_empty() {
None
} else {
Some(args.state.into_iter().collect())
},
exit_status: args.exit_status,
priority: args.priority,
content_type: args.content_type,
}
}
}
impl From<DeleteArtifactsByListArgs> for ArtifactsDeleteByUuidsReq {
fn from(args: DeleteArtifactsByListArgs) -> Self {
Self {
uuids: args.uuids,
content_type: args.content_type,
}
}
}