3 Commits

Author SHA1 Message Date
1b2a35509c feat: move also creates parent dir on destination
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
2025-08-24 17:44:17 +02:00
6129401cb5 chore(release): v0.1.2 (#11)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
chore(release): 0.1.2

Co-authored-by: cuddle-please <bot@cuddle.sh>
Reviewed-on: #11
2025-08-08 14:52:40 +02:00
1bc58a2047 feat: default to current dir if no file could be found
All checks were successful
continuous-integration/drone/push Build is passing
2025-08-08 14:52:19 +02:00
4 changed files with 36 additions and 7 deletions

View File

@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.1.2] - 2025-08-08
### Added
- default to current dir if no file could be found
### Other
- should be space instead
## [0.1.1] - 2025-08-04 ## [0.1.1] - 2025-08-04
### Fixed ### Fixed

2
Cargo.lock generated
View File

@@ -431,7 +431,7 @@ dependencies = [
[[package]] [[package]]
name = "noil" name = "noil"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"anyhow", "anyhow",

View File

@@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
version = "0.1.1" version = "0.1.2"
[workspace.dependencies] [workspace.dependencies]
noil = { path = "crates/noil" } noil = { path = "crates/noil" }

View File

@@ -40,10 +40,13 @@ pub struct EditCommand {
impl EditCommand { impl EditCommand {
pub async fn execute(&self) -> anyhow::Result<()> { pub async fn execute(&self) -> anyhow::Result<()> {
let mut small_id = Vec::with_capacity(8); let mut small_id = Vec::new();
for id in small_id.iter_mut() {
*id = encode_rand::ALPHABET for _ in 0..8 {
[rand::random_range(0..(encode_rand::ALPHABET_LEN as u8)) as usize]; small_id.push(
encode_rand::ALPHABET
[rand::random_range(0..(encode_rand::ALPHABET_LEN as u8)) as usize],
);
} }
let small_id = String::from_utf8_lossy(&small_id); let small_id = String::from_utf8_lossy(&small_id);
@@ -62,7 +65,17 @@ impl EditCommand {
.await .await
.context("create temp file for noil")?; .context("create temp file for noil")?;
let path = &self.get_path().await.context("get path")?; let path = &self
.get_path()
.await
.context("get path")
.inspect_err(|e| {
tracing::warn!(
"error: file path doesn't exist, defaulting to current working dir: {e}"
)
})
.unwrap_or_else(|_| PathBuf::from("."));
let output = get_outputs(path, true) let output = get_outputs(path, true)
.await .await
.context(format!("get output: {}", path.display()))?; .context(format!("get output: {}", path.display()))?;
@@ -315,6 +328,14 @@ pub async fn apply(input: &str, options: ApplyOptions) -> anyhow::Result<()> {
anyhow::bail!("destination already exists cannot move"); anyhow::bail!("destination already exists cannot move");
} }
if let Some(parent) = existing.path.parent()
&& !parent.exists()
{
tokio::fs::create_dir_all(&parent)
.await
.context("failed to create dest for move")?;
}
tokio::fs::rename(&existing.path, path) tokio::fs::rename(&existing.path, path)
.await .await
.context("move path")?; .context("move path")?;