-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mv and mkdir command to volumes
- Loading branch information
Showing
6 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
use super::utils::{parse_target_from_path_like, path_into_uri_safe}; | ||
use crate::{commands::volumes::utils::create_directory, state::State}; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(about = "Delete files")] | ||
#[group(skip)] | ||
pub struct Options { | ||
#[clap( | ||
help = "The path(s) to delete, in the format <deployment name or id>:<path>", | ||
required = true | ||
)] | ||
pub paths: Vec<String>, | ||
|
||
#[clap( | ||
short, | ||
long, | ||
help = "Create recursive directories if they do not exist" | ||
)] | ||
pub recursive: bool, | ||
} | ||
|
||
pub async fn handle(options: Options, state: State) -> Result<()> { | ||
for file in options.paths { | ||
let target = parse_target_from_path_like(&state, &file).await?; | ||
|
||
match target { | ||
(Some((deployment, volume)), path) => { | ||
let path = path_into_uri_safe(&path); | ||
|
||
create_directory( | ||
&state.http, | ||
&deployment.id, | ||
&volume, | ||
&path, | ||
options.recursive, | ||
) | ||
.await?; | ||
|
||
log::info!("Created directory `{file}`"); | ||
} | ||
|
||
(None, _) => { | ||
log::warn!("No deployment identifier found in `{file}`, skipping"); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use anyhow::{bail, Result}; | ||
use clap::Parser; | ||
|
||
use crate::state::State; | ||
|
||
use super::utils::{move_file, parse_target_from_path_like}; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(about = "List information about files")] | ||
#[group(skip)] | ||
pub struct Options { | ||
#[clap(help = "The path to move")] | ||
pub source: String, | ||
#[clap(help = "The path to move to")] | ||
pub target: String, | ||
} | ||
|
||
/// Handle is writte so it allows: | ||
/// hop volumes mv <deployment name or id>:<path> <deployment name or id>:<path> | ||
/// hop volumes mv <deployment name or id>:<path> <path> | ||
/// | ||
/// Which makes it easy for the user, since they don't have to specify the deployment but can | ||
pub async fn handle(options: Options, state: State) -> Result<()> { | ||
let source = parse_target_from_path_like(&state, &options.source).await?; | ||
let target = parse_target_from_path_like(&state, &options.target).await?; | ||
|
||
let (deployment, volume) = if let Some((deployment, volume)) = source.0 { | ||
(deployment, volume) | ||
} else { | ||
bail!("No deployment identifier found in `{}`", options.source); | ||
}; | ||
|
||
if let Some((deployment_target, volume_target)) = target.0 { | ||
if deployment_target.id != deployment.id || volume_target != volume { | ||
bail!("Cannot move files between deployments"); | ||
} | ||
} | ||
|
||
move_file(&state.http, &deployment.id, &volume, &source.1, &target.1).await?; | ||
|
||
log::info!("Moved `{}` to `{}`", source.1, target.1); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters