Skip to content

Commit

Permalink
Add mv command
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
fwcd committed Mar 20, 2024
1 parent e367726 commit 8ed1486
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cmd_mods!(
ln,
ls,
mkdir,
mv,
pwd,
rm,
rmdir,
Expand Down
23 changes: 23 additions & 0 deletions src/cmd/mv.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 8ed1486

Please sign in to comment.