From 423a37b5cca2e9bfc9a9e333218b8c5f63118135 Mon Sep 17 00:00:00 2001
From: Tip ten Brink <75669206+tiptenbrink@users.noreply.github.com>
Date: Thu, 16 May 2024 12:27:57 +0200
Subject: [PATCH] Large change to resolving logic
---
examples/config/end/here/there/tidploy.toml | 2 +-
.../config/move_resolve/inner/alternate.sh | 2 +
.../config/move_resolve/inner/tidploy.toml | 5 +
src/filesystem.rs | 51 +++-
src/next/api.rs | 4 +-
src/next/commands.rs | 17 +-
src/next/config.rs | 109 +++++---
src/next/errors.rs | 4 +-
src/next/git.rs | 37 ++-
src/next/resolve.rs | 210 ++++++++++++---
src/next/run.rs | 16 +-
src/next/state.rs | 245 +++++++++---------
12 files changed, 465 insertions(+), 237 deletions(-)
create mode 100755 examples/config/move_resolve/inner/alternate.sh
create mode 100644 examples/config/move_resolve/inner/tidploy.toml
diff --git a/examples/config/end/here/there/tidploy.toml b/examples/config/end/here/there/tidploy.toml
index 27441ad..224dfa4 100644
--- a/examples/config/end/here/there/tidploy.toml
+++ b/examples/config/end/here/there/tidploy.toml
@@ -1,2 +1,2 @@
[argument]
-executable = "here/there/example_im_there.sh"
\ No newline at end of file
+executable = "example_im_there.sh"
\ No newline at end of file
diff --git a/examples/config/move_resolve/inner/alternate.sh b/examples/config/move_resolve/inner/alternate.sh
new file mode 100755
index 0000000..f64b263
--- /dev/null
+++ b/examples/config/move_resolve/inner/alternate.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "I'm in here!"
\ No newline at end of file
diff --git a/examples/config/move_resolve/inner/tidploy.toml b/examples/config/move_resolve/inner/tidploy.toml
new file mode 100644
index 0000000..5521dd3
--- /dev/null
+++ b/examples/config/move_resolve/inner/tidploy.toml
@@ -0,0 +1,5 @@
+[state.address]
+path = "."
+
+[argument]
+executable = "alternate.sh"
\ No newline at end of file
diff --git a/src/filesystem.rs b/src/filesystem.rs
index ac590b1..4880efe 100644
--- a/src/filesystem.rs
+++ b/src/filesystem.rs
@@ -1,4 +1,4 @@
-use camino::{Utf8Path, Utf8PathBuf};
+use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
use directories::ProjectDirs;
use once_cell::sync::OnceCell;
use relative_path::{RelativePath, RelativePathBuf};
@@ -98,3 +98,52 @@ impl WrapToPath for RelativePathBuf {
// }
// }
}
+
+pub trait PathClean {
+ fn clean(&self) -> Utf8PathBuf;
+}
+
+impl PathClean for Utf8Path {
+ fn clean(&self) -> Utf8PathBuf {
+ clean(self)
+ }
+}
+
+impl PathClean for Utf8PathBuf {
+ fn clean(&self) -> Utf8PathBuf {
+ clean(self)
+ }
+}
+
+/// From https://github.com/danreeves/path-clean/blob/3876d7cb5367997bcda17ce165bf69c4f434cb93/src/lib.rs
+/// By Dan Reeves, used under the Apache License 2.0
+/// Changed to work for Utf8Path
+pub fn clean
(path: P) -> Utf8PathBuf
+where
+ P: AsRef,
+{
+ let mut out = Vec::new();
+
+ for comp in path.as_ref().components() {
+ match comp {
+ Utf8Component::CurDir => (),
+ Utf8Component::ParentDir => match out.last() {
+ Some(Utf8Component::RootDir) => (),
+ Some(Utf8Component::Normal(_)) => {
+ out.pop();
+ }
+ None
+ | Some(Utf8Component::CurDir)
+ | Some(Utf8Component::ParentDir)
+ | Some(Utf8Component::Prefix(_)) => out.push(comp),
+ },
+ comp => out.push(comp),
+ }
+ }
+
+ if !out.is_empty() {
+ out.iter().collect()
+ } else {
+ Utf8PathBuf::from(".")
+ }
+}
diff --git a/src/next/api.rs b/src/next/api.rs
index 4c8fe22..0a6f1f0 100644
--- a/src/next/api.rs
+++ b/src/next/api.rs
@@ -36,14 +36,14 @@ impl GlobalArguments {
fn run_in(&self) -> AddressIn {
match self.address.clone() {
Some(address) => address,
- None => AddressIn::from_run(None, None, None),
+ None => AddressIn::from_run(None, None),
}
}
fn secret_in(&self) -> AddressIn {
match self.address.clone() {
Some(address) => address,
- None => AddressIn::from_secret(None, None, None),
+ None => AddressIn::from_secret(None, None),
}
}
diff --git a/src/next/commands.rs b/src/next/commands.rs
index 2ea9991..1ed7e3a 100644
--- a/src/next/commands.rs
+++ b/src/next/commands.rs
@@ -14,10 +14,9 @@ pub struct NextSub {
/// the current directory or Git root dir
#[arg(long = "resolve-root")]
resolve_root: Option,
-
- /// Location relative to state root to stop reading configs, inclusive.
- #[arg(long = "state-root")]
- state_root: Option,
+ // /// Location relative to state root to stop reading configs, inclusive.
+ // #[arg(long = "state-root")]
+ // state_root: Option,
}
#[derive(Subcommand, Debug)]
@@ -79,7 +78,7 @@ pub enum NextCommands {
repo: Option,
#[arg(long = "local")]
- local: bool
+ local: bool,
},
}
@@ -101,7 +100,6 @@ pub enum AddressSubCommands {
pub fn match_command(next_sub: NextSub, _cmd: Command) -> Result {
let NextSub {
subcommand,
- state_root,
resolve_root,
} = next_sub;
@@ -111,7 +109,7 @@ pub fn match_command(next_sub: NextSub, _cmd: Command) -> Result {
- let addr_in = AddressIn::from_secret(resolve_root, state_path, state_root);
+ let addr_in = AddressIn::from_secret(resolve_root, state_path);
secret_command(addr_in, cwd_infer, None, None, key, None)?;
@@ -124,7 +122,7 @@ pub fn match_command(next_sub: NextSub, _cmd: Command) -> Result {
- let addr_in = AddressIn::from_run(resolve_root, state_path, state_root);
+ let addr_in = AddressIn::from_run(resolve_root, state_path);
let out = run_command(
addr_in,
git_infer,
@@ -147,8 +145,7 @@ pub fn match_command(next_sub: NextSub, _cmd: Command) -> Result {
- let addr_in =
- AddressIn::from_deploy(repo, local, git_ref, resolve_root, state_path, state_root);
+ let addr_in = AddressIn::from_deploy(repo, local, git_ref, resolve_root, state_path);
let out = run_command(
addr_in,
!cwd_infer,
diff --git a/src/next/config.rs b/src/next/config.rs
index b58b3e5..5d625fd 100644
--- a/src/next/config.rs
+++ b/src/next/config.rs
@@ -37,7 +37,8 @@ pub(crate) enum ConfigAddress {
Local {
path: String,
state_path: Option,
- state_root: Option,
+ // arg_root: Option,
+ // arg_path: Option,
},
Git {
url: String,
@@ -45,14 +46,13 @@ pub(crate) enum ConfigAddress {
git_ref: String,
target_path: Option,
state_path: Option,
- state_root: Option,
+ // arg_root: Option,
+ // arg_path: Option,
},
}
#[derive(Deserialize, Debug)]
pub(crate) struct StateConfig {
- pub(crate) state_root: Option,
- pub(crate) state_path: Option,
pub(crate) address: Option,
}
@@ -93,6 +93,13 @@ pub(crate) fn load_dploy_config(config_dir_path: &Utf8Path) -> Result Result