use clap::Subcommand;
#[derive(Subcommand, Debug)]
#[command(subcommand_required = true, arg_required_else_help = true)]
pub enum DriveCommand {
#[command(name = "ls", visible_alias = "list")]
List {
account: String,
#[arg(long)]
query: Option<String>,
},
Get {
composite: String,
},
Put {
account: String,
path: String,
},
Fetch {
composite: String,
local: String,
},
Share {
composite: String,
recipient: String,
#[arg(long)]
role: String,
},
Trash {
composite: String,
},
}
pub fn run(cmd: DriveCommand) -> netsky_core::Result<()> {
match cmd {
DriveCommand::List { account, query } => {
let value =
netsky_channels::drive::ops::list_files(&account, query.as_deref(), None, None)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?;
println!(
"{}",
serde_json::to_string_pretty(&value)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?
);
}
DriveCommand::Get { composite } => {
let value = netsky_channels::drive::ops::get_file(&composite)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?;
println!(
"{}",
serde_json::to_string_pretty(&value)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?
);
}
DriveCommand::Put { account, path } => {
let id = netsky_channels::drive::ops::upload_file(&account, &path, None, None, None)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?;
println!("uploaded: {id}");
}
DriveCommand::Fetch { composite, local } => {
let value = netsky_channels::drive::ops::download_file(&composite, &local, None)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?;
println!(
"{}",
serde_json::to_string_pretty(&value)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?
);
}
DriveCommand::Share {
composite,
recipient,
role,
} => {
let value = netsky_channels::drive::ops::share_file(&composite, &recipient, &role)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?;
println!(
"{}",
serde_json::to_string_pretty(&value)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?
);
}
DriveCommand::Trash { composite } => {
netsky_channels::drive::ops::delete_file(&composite)
.map_err(|e| netsky_core::Error::Message(e.to_string()))?;
println!("trashed: {composite}");
}
}
Ok(())
}