From 8ed14863544b6c06fd7fc44b6eb16741bba57c6b Mon Sep 17 00:00:00 2001 From: fwcd Date: Wed, 20 Mar 2024 23:38:10 +0100 Subject: [PATCH] Add mv command Fixes #7 --- src/cmd/mod.rs | 1 + src/cmd/mv.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/cmd/mv.rs diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index fbebd96..9f595aa 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -25,6 +25,7 @@ cmd_mods!( ln, ls, mkdir, + mv, pwd, rm, rmdir, diff --git a/src/cmd/mv.rs b/src/cmd/mv.rs new file mode 100644 index 0000000..3850895 --- /dev/null +++ b/src/cmd/mv.rs @@ -0,0 +1,23 @@ +use anyhow::Result; +use clap::Parser; +use lighthouse_client::protocol::Value; + +use crate::{context::Context, path::VirtualPathBuf}; + +#[derive(Parser)] +#[command(bin_name = "mv")] +struct Args { + #[arg(help = "The source path, i.e. the resource to move")] + src_path: VirtualPathBuf, + #[arg(help = "The destination path")] + dest_path: VirtualPathBuf, +} + +pub async fn invoke(args: &[&str], ctx: &mut Context) -> Result<()> { + let args = Args::try_parse_from(args)?; + let [src_path, dest_path] = [args.src_path, args.dest_path].map(|p| ctx.cwd.join(p)); + let payload: Value = ctx.lh.get(&src_path.as_lh_vec()).await?.payload; + ctx.lh.post(&dest_path.as_lh_vec(), payload).await?; + ctx.lh.delete(&src_path.as_lh_vec()).await?; + Ok(()) +}