From eaf2d266afc07fba6feb658cd56aa904f4f758bc Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Thu, 30 May 2024 13:59:45 +0200 Subject: [PATCH 1/3] add `inbreeding watch` --- bins/inbreeding/mod.nu | 1 + bins/inbreeding/watch.nu | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 bins/inbreeding/watch.nu diff --git a/bins/inbreeding/mod.nu b/bins/inbreeding/mod.nu index f3bdbd9d..4059fa7c 100644 --- a/bins/inbreeding/mod.nu +++ b/bins/inbreeding/mod.nu @@ -1,4 +1,5 @@ export use build.nu +export use watch.nu export use run.nu export use inspect.nu export use load.nu diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu new file mode 100644 index 00000000..7dacfcaa --- /dev/null +++ b/bins/inbreeding/watch.nu @@ -0,0 +1,12 @@ +use consts.nu CACHE +use path.nu [ "remove-cache-prefix" ] + +export def main [] { + watch $CACHE { |op, path, new_path| + if $op == "Create" { + let now = date now | format date "%Y-%m-%d %H:%M:%S" + let p = $path | remove-cache-prefix | parse "{seed}/{exp}/{id}" | into record + $"($p.seed | str substring 0..7) ($p.exp) ($p.id | str substring 0..7) at ($now)" + } + } +} -- GitLab From 82a77996cc3fecbaeeac3ebaf4fce4f1f3415c92 Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Thu, 30 May 2024 14:08:14 +0200 Subject: [PATCH 2/3] add a guard in case the format is bad this commit also inverts the condition and uses an early return. --- bins/inbreeding/watch.nu | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu index 7dacfcaa..1ff05085 100644 --- a/bins/inbreeding/watch.nu +++ b/bins/inbreeding/watch.nu @@ -3,10 +3,17 @@ use path.nu [ "remove-cache-prefix" ] export def main [] { watch $CACHE { |op, path, new_path| - if $op == "Create" { - let now = date now | format date "%Y-%m-%d %H:%M:%S" - let p = $path | remove-cache-prefix | parse "{seed}/{exp}/{id}" | into record - $"($p.seed | str substring 0..7) ($p.exp) ($p.id | str substring 0..7) at ($now)" + if $op != "Create" { + return } + + let now = date now | format date "%Y-%m-%d %H:%M:%S" + let p = $path | remove-cache-prefix | parse "{seed}/{exp}/{id}" | into record + + if $p == {} { + return $"($path | remove-cache-prefix) created" + } + + $"($p.seed | str substring 0..7) ($p.exp) ($p.id | str substring 0..7) at ($now)" } } -- GitLab From e7a3c54605af52c03c327a27dc5ca054085ca2bf Mon Sep 17 00:00:00 2001 From: "a.stevan" <antoine.stevan@isae-supaero.fr> Date: Thu, 30 May 2024 15:31:56 +0200 Subject: [PATCH 3/3] fix the format --- bins/inbreeding/watch.nu | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bins/inbreeding/watch.nu b/bins/inbreeding/watch.nu index 1ff05085..69a5bdef 100644 --- a/bins/inbreeding/watch.nu +++ b/bins/inbreeding/watch.nu @@ -11,9 +11,10 @@ export def main [] { let p = $path | remove-cache-prefix | parse "{seed}/{exp}/{id}" | into record if $p == {} { - return $"($path | remove-cache-prefix) created" + let p = $path | remove-cache-prefix | parse "{seed}/{exp}" | into record + return $"($p.seed | str substring 0..7) ($p.exp) at ($now)" } - $"($p.seed | str substring 0..7) ($p.exp) ($p.id | str substring 0..7) at ($now)" + $"($p.seed | str substring 0..7) ($p.exp) ($p.id | str substring 0..7) at ($now)" } } -- GitLab