From 1f43185e71c7422309041088a3a40f660a34aadd Mon Sep 17 00:00:00 2001
From: Anton Dyudin <ohAitch@gmail.com>
Date: Wed, 27 May 2015 19:46:58 -0700
Subject: [PATCH] cli utils, yet untyped

---
 base/ape/dojo/core.hook    |  3 ++-
 base/ape/hood/core.hook    | 13 ++++++++++++-
 base/arvo/gall.hoon        | 17 ++++++++---------
 base/cat/cat/gate.hook     | 28 ++++++++++++++++++++++++++++
 base/cat/cat/pretty.hoon   | 25 +++++++++++++++++++++++++
 base/cat/hood/cp/gate.hook |  1 +
 base/cat/hood/mv/gate.hook |  1 +
 base/cat/hood/rm/gate.hook |  1 +
 base/cat/ls/gate.hook      | 11 +++++++++++
 base/cat/ls/subdir.hoon    | 20 ++++++++++++++++++++
 base/cat/tree/gate.hook    | 20 ++++++++++++++++++++
 base/lib/kiln/core.hook    | 36 ++++++++++++++++++++++++++++++------
 12 files changed, 159 insertions(+), 17 deletions(-)
 create mode 100644 base/cat/cat/gate.hook
 create mode 100644 base/cat/cat/pretty.hoon
 create mode 100644 base/cat/hood/cp/gate.hook
 create mode 100644 base/cat/hood/mv/gate.hook
 create mode 100644 base/cat/hood/rm/gate.hook
 create mode 100644 base/cat/ls/gate.hook
 create mode 100644 base/cat/ls/subdir.hoon
 create mode 100644 base/cat/tree/gate.hook

diff --git a/base/ape/dojo/core.hook b/base/ape/dojo/core.hook
index b65b9d8d6..3c967f083 100644
--- a/base/ape/dojo/core.hook
+++ b/base/ape/dojo/core.hook
@@ -450,7 +450,8 @@
         dy-amok(var (~(put by var) p.mad (~(got by rez) p.q.mad)))
       ::
           %show
-        (dy-rash %tan (sell q:(~(got by rez) p.p.mad)) ~)
+        =+  cay=(~(got by rez) p.p.mad)
+        (dy-rash %tan ?+(p.cay [(sell q.cay)]~ %tang ;;(tang q.q.cay)))
       ==
     ::
     ++  dy-edit                                         ::  handle edit
diff --git a/base/ape/hood/core.hook b/base/ape/hood/core.hook
index 7463e67da..2da6dc24e 100644
--- a/base/ape/hood/core.hook
+++ b/base/ape/hood/core.hook
@@ -1,4 +1,4 @@
-::                                                      ::  ::
+ ::                                                      ::  ::
 ::::  /hook/core/hood/ape                               ::  ::
   ::                                                    ::  ::
 /?  314                                                 ::  zuse version
@@ -110,6 +110,17 @@
   |=  [from dill-belt]
   (ably (poke-dill-belt:(drum-work [hid +<-] (able %drum)) +<+))
 ::
+++  from-kiln
+  =-  [wrap=- *kiln-work]
+  |*  fun=_=>(*kiln-work |=(* abet))
+  |=  [from _+<.fun]
+  =.  +>.fun  (kiln-work [hid +<-] (able %kiln))
+  (ably (fun +<+))
+::
+++  poke-kiln-cp  (wrap poke-cp):from-kiln
+++  poke-kiln-rm  (wrap poke-rm):from-kiln
+++  poke-kiln-mv  (wrap poke-mv):from-kiln 
+::
 ++  poke-will                                           ::
   |=  [from (unit will)]
   (ably (poke-will:(helm-work [hid +<-] (able %helm)) +<+))
diff --git a/base/arvo/gall.hoon b/base/arvo/gall.hoon
index 0b64e1cc0..933922f6d 100644
--- a/base/arvo/gall.hoon
+++ b/base/arvo/gall.hoon
@@ -367,7 +367,7 @@
   ++  mo-cook                                           ::  take in /use
     |=  [pax=path hin=(hypo sign-arvo)]
     ^+  +>
-    ?.  ?=([@ @ ?(%inn %out %enn) *] pax)
+    ?.  ?=([@ @ ?(%inn %out %cay) *] pax)
       ~&  [%mo-cook-bad-pax pax]
       !!
     =+  dap=`@tas`i.pax
@@ -376,11 +376,11 @@
     =+  vax=(slot 3 `vase`hin)
     ?-  i.t.t.pax
       %inn  ap-abet:(ap-pour:pap t.t.t.pax (slot 3 `vase`hin))      
-      %enn  ?.  ?=([%e %sigh *] q.hin)
+      %cay  ?.  ?=([%e %sigh *] q.hin)
               ~&  [%mo-cook-weird q.hin]
               ~&  [%mo-cook-weird-path pax]
               +>.$
-            ap-abet:(ap-sigh:pap t.t.t.pax +>.q.hin)
+            ap-abet:(ap-purr:pap +<.q.hin t.t.t.pax +>.q.hin)
     ::
       %out  ?.  ?=([%g %unto *] q.hin)
               ~&  [%mo-cook-weird q.hin]
@@ -685,7 +685,7 @@
       ?.  &(?=(^ pux) (levy u.pux (sane %ta)))
         [%| (ap-suck "move: malformed path")]
       :^  %&  sto  %pass
-      :-  [(scot %p q.q.pry) %enn u.pux]
+      :-  [(scot %p q.q.pry) %cay u.pux]
       [%hiss q.q.vax [p.q.gaw (slot 3 (spec gaw))]]
     ::
     ++  ap-move-mess                                    ::  extract path, target
@@ -857,13 +857,13 @@
       ?^  cam  (ap-lame -.q.vax u.cam)
       +>.$
     ::
-    ++  ap-sigh                                         ::  http response
-      |=  [pax=path cag=cage]
+    ++  ap-purr                                         ::  unwrap take
+      |=  [wha=term pax=path cag=cage]
       ^+  +>
       =.  q.cag  (spec q.cag)
-      =+  cug=(ap-find [%sigh p.cag pax])
+      =+  cug=(ap-find [wha p.cag pax])
       ?~  cug
-        (ap-lame %sigh (ap-suck "sigh: no {<`path`[p.cag pax]>}"))
+        (ap-lame wha (ap-suck "{(trip wha)}: no {<`path`[p.cag pax]>}"))
       =+  ^=  arg  ^-  vase
           %-  slop
           ?:  =(0 p.u.cug)
@@ -1027,7 +1027,6 @@
         %merg  `%c
         %plug  `%c
         %them  `%e
-        %hiss  `%e
         %want  `%a
       ==
     --
diff --git a/base/cat/cat/gate.hook b/base/cat/cat/gate.hook
new file mode 100644
index 000000000..ba9538e1f
--- /dev/null
+++ b/base/cat/cat/gate.hook
@@ -0,0 +1,28 @@
+::  ConCATenate file listings
+::  
+::::  /hook/gate/cat/cat
+  ::
+//  /%%%/ls/subdir
+//  /%%/pretty
+!:
+::::
+  ::
+|=  [^ [arg=(list path)] ~]
+=-  tang/(zing -)
+%+  turn  arg
+|=  pax=path
+^-  tang
+=+  ark=;;(arch .^(%cy pax))
+?^  q.ark
+  [leaf/(spud pax) (pretty-file .^(%cx pax))]
+?-     r.ark                                          ::  handle ambiguity
+    ~
+  [rose/[" " `~]^~[leaf/"~" (smyt pax)]]~
+    [[@t ~] ~ ~]
+  $(pax (welp pax /[p.n.r.ark]))
+    *
+  =-  [palm/[": " ``~]^-]~
+  :~  rose/[" " `~]^~[leaf/"*" (smyt pax)] 
+      `tank`(subdir pax r.ark)
+  ==
+==
diff --git a/base/cat/cat/pretty.hoon b/base/cat/cat/pretty.hoon
new file mode 100644
index 000000000..d41cf607d
--- /dev/null
+++ b/base/cat/cat/pretty.hoon
@@ -0,0 +1,25 @@
+!:
+|%
+++  pretty-noun
+  |=  pri=*  ^-  tank
+  ?~  pri
+    leaf/"~"
+  ?@  pri
+    leaf/?:(((sane %tas) pri) <`@tas`pri> <pri>)
+  =<  rose/[" " ?:(- "~[" "[") "]"]^+
+  |-  ^-  [? (list tank)]
+  ?~  +.pri
+    [& ^$(pri -.pri) ~]
+  ?@  +.pri
+    [| ^$(pri -.pri) ^$(pri +.pri) ~]
+  [+< - +>]:[^$(pri -.pri) $(pri +.pri)]
+::
+++  vale-cord  |=(a=cord `?`(levy (trip a) |=(b=@ |((gte b 32) =(10 b)))))
+::
+++  pretty-file
+  =+  wain-to-tang=|=(a=wain (turn a |=(b=cord leaf/(trip b))))
+  |=  fyl=*  ^-  tang
+  =+  `(unit wain)`?@(fyl `(lore fyl) ((soft wain) fyl))
+  ?^  -  (wain-to-tang u)
+  [(pretty-noun fyl)]~
+--
diff --git a/base/cat/hood/cp/gate.hook b/base/cat/hood/cp/gate.hook
new file mode 100644
index 000000000..72e380578
--- /dev/null
+++ b/base/cat/hood/cp/gate.hook
@@ -0,0 +1 @@
+|=([^ [input=path output=path ~] ~] kiln-mv/[input output])
diff --git a/base/cat/hood/mv/gate.hook b/base/cat/hood/mv/gate.hook
new file mode 100644
index 000000000..4dd6cc488
--- /dev/null
+++ b/base/cat/hood/mv/gate.hook
@@ -0,0 +1 @@
+|=([^ [input=path output=path ~] ~] kiln-cp/[input output])
diff --git a/base/cat/hood/rm/gate.hook b/base/cat/hood/rm/gate.hook
new file mode 100644
index 000000000..04af9e024
--- /dev/null
+++ b/base/cat/hood/rm/gate.hook
@@ -0,0 +1 @@
+|=([^ [input=path ~] ~] kiln-rm/input)
diff --git a/base/cat/ls/gate.hook b/base/cat/ls/gate.hook
new file mode 100644
index 000000000..28ab0f0bb
--- /dev/null
+++ b/base/cat/ls/gate.hook
@@ -0,0 +1,11 @@
+::  LiSt directory subnodes
+::
+::::  /hook/gate/ls/cat
+  ::
+//  /%%/subdir
+!:
+::::
+  ::
+|=  [^ [arg=path ~] ~]
+=+  lon=((hard arch) .^(%cy arg))
+tang/[?~(r.lon leaf/"~" (subdir arg r.lon))]~
diff --git a/base/cat/ls/subdir.hoon b/base/cat/ls/subdir.hoon
new file mode 100644
index 000000000..a665d47ba
--- /dev/null
+++ b/base/cat/ls/subdir.hoon
@@ -0,0 +1,20 @@
+|%
+++  subdir
+  |=  [pax=path des=(map ,@t ,~)]
+  ^-  tank
+  :+  %rose  [" " `~]
+  %+  turn  (sort (~(tap by des)) aor)
+  |=  [kid=@ta ~]
+  =+  paf=`path`/[kid]
+  =-  :+  %rose  ["/" ~ ?:(dir "/" ~)]
+      (turn paf |=(a=span leaf/(trip a)))
+  |-  ^-  [dir=? paf=path]
+  =+  arf=;;(arch .^(%cy (weld pax paf)))
+  ?^  q.arf  
+    [| paf]
+  ?~  r.arf
+    [& paf]  ::  !!
+  ?.  ?=([^ ~ ~] r.arf)
+    [& paf]
+  $(paf (welp paf /[p.n.r.arf]))
+--
diff --git a/base/cat/tree/gate.hook b/base/cat/tree/gate.hook
new file mode 100644
index 000000000..203cf0696
--- /dev/null
+++ b/base/cat/tree/gate.hook
@@ -0,0 +1,20 @@
+::  Tree view recursive directory contents
+::  
+::::  /hook/gate/tree/cat
+  ::
+!:
+::::
+  ::
+|=  [^ [pax=path fla=$|(~ [%full ~])] ~]
+=+  len=(lent pax)
+=+  rend=?^(fla dank:ut |=(a=path (dank:ut (slag len a))))
+:-  %tang
+|-  ^-  tang
+=+  ark=;;(arch .^(cy/pax))
+=-  ?~  q.ark  -
+    [(rend pax) -]
+%-  zing
+%+  turn
+  (sort (~(tap by r.ark)) aor)
+|=  [a=@t ~] 
+^$(pax (welp pax /[a]))
diff --git a/base/lib/kiln/core.hook b/base/lib/kiln/core.hook
index 035e32b11..bbf5f0dbe 100644
--- a/base/lib/kiln/core.hook
+++ b/base/lib/kiln/core.hook
@@ -2,10 +2,17 @@
 ::::  /hook/core/kiln/lib                               ::  ::
   ::                                                    ::  ::
 /?  310                                                 ::  version
+::  /+  mean  XX
 ::                                                      ::  ::
 ::::                                                    ::  ::
   ::                                                    ::  ::
 |%                                                      ::  ::
+++  mean
+  |=  a=tang 
+  ?~  a  !!
+  ~>  %mean.|.(i.a)
+  $(a t.a)
+::
 ++  kiln-part  ,[%kiln %0 kiln-pith]                    ::  kiln state
 ++  kiln-pith                                           ::
     $:  rem=(map desk kiln-desk)                        ::
@@ -35,6 +42,8 @@
         sud=desk                                        ::
         gim=?(%auto germ)                               ::
     ==                                                  ::
+++  hood-cp  [input=path output=path]          ::
+++  hood-mv  [input=path output=path]
 --                                                      ::
 ::                                                      ::  ::
 ::::                                                    ::  ::
@@ -81,6 +90,25 @@
     |=  hood-merge
     abet:abet:(merge:(work syd) ali sud gim)
   ::
+  ++  do-info
+    |=  [mez=tape pax=path tor=toro]
+    =+  syd=q:(need (tome pax))
+    =-  abet:abet:(spam:(work syd) leaf/mez ~)
+    (emit %info /kiln our tor)
+  ++  poke-rm  |=(a=path (do-info "removed" a (fray a)))
+  ++  poke-cp
+    |=  [input=path output=path]
+    %^  do-info  "copied"  input
+    ?>  =(-:(flop input) -:(flop output))
+    (foal output -:(flop input) %noun .^(%cx input))    ::  XX type
+  ::
+  ++  poke-mv
+    |=  [input=path output=path] 
+    %^  do-info  "moved"  input
+    ?>  =(-:(flop input) -:(flop output))
+    %+  furl  (fray output)
+    (foal output -:(flop input) %noun .^(%cx input))
+  ::
   ++  take  |=(way=wire ?>(?=([@ ~] way) (work i.way))) ::  general handler
   ++  take-mere                                         ::
     |=  [way=wire are=(each (set path) (pair term tang))]
@@ -116,12 +144,8 @@
       !!
     ::
     ++  ford-fail
-      |=  tan=tang  
-      ~|  %ford-fail
-      |-
-      ?~  tan  !!
-      ~>  %mean.|.(i.tan)           ::  interpolate into stack trace
-      $(tan t.tan) 
+      |=(tan=tang ~|(%ford-fail (mean tan)))
+      
     ::
     ++  unwrap-tang
       |*  res=(each ,* tang)