From 69b5c6fcb05ee8741f547f2fcbba051f9ac62fa4 Mon Sep 17 00:00:00 2001 From: David Kerschner Date: Tue, 2 Oct 2018 12:26:16 -0700 Subject: [PATCH] Issue #61 Extracted %ask generator methods from sur/sole and put them in a core under lib/sole Fixed names in existing generators --- gen/curl-hiss.hoon | 9 ++++----- gen/curl.hoon | 11 +++++------ gen/dns/authority.hoon | 22 ++++++++++++---------- gen/hood/begin.hoon | 27 +++++++++++++-------------- gen/hood/init-auth-basic.hoon | 20 ++++++++++---------- gen/hood/init-oauth1.hoon | 21 ++++++++++----------- gen/hood/init-oauth2.hoon | 21 ++++++++++----------- gen/hood/init-oauth2/google.hoon | 15 +++++++-------- gen/moon.hoon | 9 ++++----- gen/pope.hoon | 15 +++++++-------- lib/sole.hoon | 32 ++++++++++++++++++++++++++++++++ sur/sole.hoon | 31 +------------------------------ 12 files changed, 115 insertions(+), 118 deletions(-) diff --git a/gen/curl-hiss.hoon b/gen/curl-hiss.hoon index 6478b63657..1b57f6a658 100644 --- a/gen/curl-hiss.hoon +++ b/gen/curl-hiss.hoon @@ -3,15 +3,14 @@ :::: /hoon/curl-hiss/gen :: /? 310 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse -=, sole +=, ask:sole :- %get |= {^ {a/hiss ~} usr/iden} -^- (sole-request (cask httr)) +^- (sole-request:sole (cask httr)) ?. ?=($get p.q.a) ~| %only-get-requests-supported-in-generators :: XX enforced? !! :- *tang :^ %| `usr `hiss`a -|=(hit/httr (sole-so %httr hit)) +|=(hit/httr (output %httr hit)) diff --git a/gen/curl.hoon b/gen/curl.hoon index a44d22cf20..bf7c0c9de2 100644 --- a/gen/curl.hoon +++ b/gen/curl.hoon @@ -3,12 +3,11 @@ :::: /hoon/curl/gen :: /? 310 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse -=, sole +=, ask:sole :- %get |= {^ {a/tape ~} ~} -^- (sole-request (cask httr)) -%+ sole-at (scan a auri:urlp) +^- (sole-request:sole (cask httr)) +%+ curl (scan a auri:urlp) |= hit/httr -(sole-so %httr hit) +(output %httr hit) diff --git a/gen/dns/authority.hoon b/gen/dns/authority.hoon index 5f2235a9d1..1597d2aebb 100644 --- a/gen/dns/authority.hoon +++ b/gen/dns/authority.hoon @@ -2,29 +2,31 @@ :: :::: /hoon/authority/dns/gen :: -/- dns, sole -=, [dns sole] +/- dns +/+ sole +=, dns +=, ask:sole :- %ask |= $: [now=@da eny=@uvJ bec=beak] [arg=$@(~ [dom=path ~])] ~ == -^- (sole-result [%dns-authority authority]) +^- (sole-result:sole [%dns-authority authority]) =- ?~ arg - (fun.q.q [%& dom.arg]) -%+ sole-lo +%+ prompt [%& %dns-domain "dns domain: "] -%+ sole-go thos:de-purl:html +%+ parse thos:de-purl:html |= hot=host:eyre ?: ?=(%| -.hot) ~|(%ips-unsupported !!) -%+ sole-lo +%+ prompt [%& %project "gcloud project: "] -%+ sole-go urs:ab +%+ parse urs:ab |= project=@ta -%+ sole-lo +%+ prompt [%& %zone "dns zone: "] -%+ sole-go urs:ab +%+ parse urs:ab |= zone=@ta -%+ sole-so %dns-authority +%+ output %dns-authority [p.hot %gcloud project zone] diff --git a/gen/hood/begin.hoon b/gen/hood/begin.hoon index 043ce5127e..6f3608d63c 100644 --- a/gen/hood/begin.hoon +++ b/gen/hood/begin.hoon @@ -3,8 +3,7 @@ :::: /hoon/begin/hood/gen :: /? 310 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse :: :::: @@ -13,34 +12,34 @@ ++ begs {his/@p tic/@p yen/@t ges/gens} ++ scug |*({a/@ b/(pole)} ?~(b ~ ?~(a ~ [-.b $(b +.b, a (dec a))]))) -- -=, sole +=, ask:sole :- %ask |= $: {now/@da eny/@uvJ bec/beak} {arg/_(scug *@ *{his/@p tic/@p ~})} safety/?($off $on) == -^- (sole-result (cask begs)) +^- (sole-result:sole (cask begs)) ?. =(safety %off) - %+ sole-yo + %+ print :- %leaf "|begin is deprecated, please invoke urbit with -w [name] -t [ticket]" - sole-no + no-result =- - -%+ sole-lo +%+ prompt [%& %helm-begin "your urbit: ~"] -%+ sole-go fed:ag +%+ parse fed:ag |= his/@p -%+ sole-lo +%+ prompt [%& %helm-ticket "your ticket: ~"] -%+ sole-go fed:ag +%+ parse fed:ag |= tic/@p -%+ sole-lo +%+ prompt [%& %helm-entropy "some entropy: "] -%+ sole-go (boss 256 (more gon qit)) +%+ parse (boss 256 (more gon qit)) |= yen/@t =+ ney=(shax yen) -%+ sole-yo `tank`[%leaf "entropy check: {(scow %p `@p`(mug ney))}"] -%+ sole-so %helm-begin +%+ print `tank`[%leaf "entropy check: {(scow %p `@p`(mug ney))}"] +%+ output %helm-begin :* his tic ney diff --git a/gen/hood/init-auth-basic.hoon b/gen/hood/init-auth-basic.hoon index d6aeafc848..6f63f117c0 100644 --- a/gen/hood/init-auth-basic.hoon +++ b/gen/hood/init-auth-basic.hoon @@ -3,32 +3,32 @@ :::: /hoon/init-auth-basic/hood/gen :: /? 314 -/- sole +/+ sole :: :::: :: -=, sole +=, ask:sole :- %ask |= $: {now/@da eny/@uvJ bec/beak} {arg/$@(~ {dom/path ~})} ~ == -^- (sole-result {$write-sec-atom p/host:eyre q/@}) +^- (sole-result:sole {$write-sec-atom p/host:eyre q/@}) =- ?~ arg - (fun.q.q [%& dom.arg]) -%+ sole-lo +%+ prompt [%& %oauth-hostname "api hostname: https://"] -%+ sole-go thos:de-purl:html +%+ parse thos:de-purl:html |= hot/host:eyre ?: ?=(%| -.hot) ~|(%ips-unsupported !!) -%+ sole-lo +%+ prompt [%& %auth-user "username: "] -%+ sole-go (boss 256 (star ;~(less col prn))) +%+ parse (boss 256 (star ;~(less col prn))) |= usr/@t -%+ sole-lo +%+ prompt [%| %auth-passwd "password: "] -%+ sole-go (boss 256 (star prn)) +%+ parse (boss 256 (star prn)) |= pas/@t -%+ sole-so %write-sec-atom :: XX typed pair +%+ output %write-sec-atom :: XX typed pair [hot (crip (en-base64:mimes:html (rap 3 usr ':' pas ~)))] diff --git a/gen/hood/init-oauth1.hoon b/gen/hood/init-oauth1.hoon index 44b9191ac4..0852217a49 100644 --- a/gen/hood/init-oauth1.hoon +++ b/gen/hood/init-oauth1.hoon @@ -3,34 +3,33 @@ :::: /hoon/init-oauth1/hood/gen :: /? 314 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse :: :::: :: -=, sole +=, ask:sole :- %ask |= $: {now/@da eny/@uvJ bec/beak} {arg/$@(~ {dom/path ~})} ~ == -^- (sole-result {$write-sec-atom p/host q/@}) +^- (sole-result:sole {$write-sec-atom p/host q/@}) =- ?~ arg - (fun.q.q [%& dom.arg]) -%+ sole-lo +%+ prompt [%& %oauth-hostname "api hostname: https://"] -%+ sole-go thos:urlp +%+ parse thos:urlp |= hot/host ?: ?=(%| -.hot) ~|(%ips-unsupported !!) -%+ sole-lo +%+ prompt [%& %oauth-client "consumer key: "] -%+ sole-go (boss 256 (star prn)) +%+ parse (boss 256 (star prn)) |= key/@t -%+ sole-lo +%+ prompt [%& %oauth-secret "consumer secret: "] -%+ sole-go (boss 256 (star prn)) +%+ parse (boss 256 (star prn)) |= sec/@t -%+ sole-so %write-sec-atom :: XX typed pair +%+ output %write-sec-atom :: XX typed pair [hot (of-wain:format key sec ~)] diff --git a/gen/hood/init-oauth2.hoon b/gen/hood/init-oauth2.hoon index 1727eabb8c..24f458b497 100644 --- a/gen/hood/init-oauth2.hoon +++ b/gen/hood/init-oauth2.hoon @@ -3,34 +3,33 @@ :::: /hoon/init-oauth2/hood/gen :: /? 314 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse :: :::: :: -=, sole +=, ask:sole :- %ask |= $: {now/@da eny/@uvJ bec/beak} {arg/$@(~ {dom/path ~})} ~ == -^- (sole-result {$write-sec-atom p/host:eyre q/@}) +^- (sole-result:sole {$write-sec-atom p/host:eyre q/@}) =- ?~ arg - (fun.q.q [%& dom.arg]) -%+ sole-lo +%+ prompt [%& %oauth-hostname "api hostname: https://"] -%+ sole-go thos:de-purl:html +%+ parse thos:de-purl:html |= hot/host:eyre ?: ?=(%| -.hot) ~|(%ips-unsupported !!) -%+ sole-lo +%+ prompt [%& %oauth-client "client id: "] -%+ sole-go (boss 256 (star prn)) +%+ parse (boss 256 (star prn)) |= cid/@t -%+ sole-lo +%+ prompt [%& %oauth-secret "client secret: "] -%+ sole-go (boss 256 (star prn)) +%+ parse (boss 256 (star prn)) |= cis/@t -%+ sole-so %write-sec-atom :: XX typed pair +%+ output %write-sec-atom :: XX typed pair [hot (of-wain:format cid cis ~)] diff --git a/gen/hood/init-oauth2/google.hoon b/gen/hood/init-oauth2/google.hoon index 45cd53c59e..6692334f75 100644 --- a/gen/hood/init-oauth2/google.hoon +++ b/gen/hood/init-oauth2/google.hoon @@ -3,13 +3,12 @@ :::: /hoon/google/init-oauth2/hood/gen :: /? 314 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse :: :::: :: -=, sole +=, ask:sole =, html =, format :- %ask @@ -17,17 +16,17 @@ {arg/$@(~ {jon/json ~})} ~ == -^- (sole-result {$write-sec-atom p/host:eyre q/@}) -%+ sole-yo leaf+"Accepting credentials for https://*.googleapis.com" +^- (sole-result:sole {$write-sec-atom p/host:eyre q/@}) +%+ print leaf+"Accepting credentials for https://*.googleapis.com" =+ hot=[%& /com/googleapis] =- ?~ arg - (fun.q.q jon.arg) -%+ sole-lo +%+ prompt [%& %oauth-json "json credentials: "] -%+ sole-go apex:de-json +%+ parse apex:de-json |= jon/json =+ ~| bad-json+jon =- `{cid/@t cis/@t}`(need (rep jon)) rep=(ot web+(ot 'client_id'^so 'client_secret'^so ~) ~):dejs-soft:format -%+ sole-so %write-sec-atom :: XX typed pair +%+ output %write-sec-atom :: XX typed pair [hot (of-wain:format cid cis ~)] diff --git a/gen/moon.hoon b/gen/moon.hoon index 0a7af7e1c8..a08ae85287 100644 --- a/gen/moon.hoon +++ b/gen/moon.hoon @@ -3,10 +3,9 @@ :::: /hoon/moon/gen :: /? 310 -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse -=, sole +=, ask:sole :: :::: :: @@ -17,9 +16,9 @@ == =/ ran (clan p.bec) ?: ?=({?($earl $pawn)} ran) - %- sole-so + %- output :- %tang :_ ~ leaf+"can't create a moon from a {?:(?=($earl ran) "moon" "comet")}" =/ mon (mix (lsh 5 1 (end 5 1 eny)) p.bec) =/ tic .^(@ /a/(scot %p p.bec)/tick/(scot %da now)/(scot %p mon)) -(sole-so [%tang leaf+"ticket: {<`@p`tic>}" leaf+"moon: {<`@p`mon>}" ~]) +(output [%tang leaf+"ticket: {<`@p`tic>}" leaf+"moon: {<`@p`mon>}" ~]) diff --git a/gen/pope.hoon b/gen/pope.hoon index 7303c4ccce..d850a7c6a1 100644 --- a/gen/pope.hoon +++ b/gen/pope.hoon @@ -4,24 +4,23 @@ :: /? 310 :: Input twitter keys -/- sole -/+ old-zuse +/+ sole, old-zuse =, old-zuse :: =+ cryp=crub -=+ [sole] +=, ask:sole :- %ask |= $: {now/@da eny/@uvJ bec/beak} {{who/ship ~} ~} == -^- (sole-result (cask tang)) -%+ sole-yo leaf+"generating carrier {(scow %p who)} (#{(scow %ud who)})" -%+ sole-lo [%| %pope-pass "passphrase: "] -%+ sole-go (boss 256 (star prn)) +^- (sole-result:sole (cask tang)) +%+ print leaf+"generating carrier {(scow %p who)} (#{(scow %ud who)})" +%+ prompt [%| %pope-pass "passphrase: "] +%+ parse (boss 256 (star prn)) |= fra/@t =+ bur=(shaz (add who (shaz fra))) =+ arc=(pit:nu:cryp 512 bur) -%+ sole-so %tang +%+ output %tang :~ leaf+"generator: {(scow %uw bur)}" leaf+"fingerprint: {(scow %uw fig:ex:arc)}" == diff --git a/lib/sole.hoon b/lib/sole.hoon index d71f9a07d4..6963d10cd9 100644 --- a/lib/sole.hoon +++ b/lib/sole.hoon @@ -138,4 +138,36 @@ =+ dat=(transmute [%mor leg] [%ins pos `@c`0]) ?> ?=($ins -.dat) p.dat +++ ask + |% + ++ output :: construct result + |* pro/* :: + [p=*(list tank) q=[%& p=[~ u=pro]]] :: + :: :: + ++ print :: add output tank + |* {tan/tank res/(sole-result)} :: + ?@ res res :: + [p=[i=tan t=p.res] q=q.res] :: + :: :: + ++ prompt :: construct prompt + |* {pom/sole-prompt mor/(sole-dialog)} :: + [p=*(list tank) q=[%| p=pom q=mor]] :: + :: :: + ++ curl :: fetch url + =| usr/knot :: + |* {pul/_purl:eyre fun/$-(httr:eyre *)} :: + :- p=*(list tank) :: + q=[%| p=`usr q=[pul %get ~ ~] r=fun] :: + :: :: + ++ no-result :: empty result + [p=*(list tank) q=[%& ~]] :: + :: :: + ++ parse :: parse by rule + |* {sef/rule fun/$-(* *)} :: + |= txt/sole-input :: + =+ vex=(sef [0 0] txt) :: + ?: |(!=((lent txt) q.p.vex) ?=($~ q.vex)) :: + q.p.vex :: + (fun p.u.q.vex) :: + -- -- diff --git a/sur/sole.hoon b/sur/sole.hoon index fa6304311b..3e589e5899 100644 --- a/sur/sole.hoon +++ b/sur/sole.hoon @@ -70,7 +70,7 @@ %+ each (unit out) :: ~ is abort (pair sole-prompt (sole-dialog out)) :: ask and continue :: :: -++ sole-request :: scraper result +++ sole-request :: scraper result |* out/$-(* *) :: output structure %+ pair (list tank) :: %+ each (unit out) :: ~ is abort @@ -91,33 +91,4 @@ {{now/@da eny/@uvJ bek/beak} {,+<- ,+<+}} :: :: :: :: :: -++ sole-so :: construct result - |* pro/* :: - [p=*(list tank) q=[%& p=[~ u=pro]]] :: -:: :: -++ sole-yo :: add output tank - |* {tan/tank res/(sole-result)} :: - ?@ res res :: - [p=[i=tan t=p.res] q=q.res] :: -:: :: -++ sole-lo :: construct prompt - |* {pom/sole-prompt mor/(sole-dialog)} :: - [p=*(list tank) q=[%| p=pom q=mor]] :: -:: :: -++ sole-at :: fetch url - =| usr/knot :: - |* {pul/_purl:eyre fun/$-(httr:eyre *)} :: - :- p=*(list tank) :: - q=[%| p=`usr q=[pul %get ~ ~] r=fun] :: -:: :: -++ sole-no :: empty result - [p=*(list tank) q=[%& ~]] :: -:: :: -++ sole-go :: parse by rule - |* {sef/rule fun/$-(* *)} :: - |= txt/sole-input :: - =+ vex=(sef [0 0] txt) :: - ?: |(!=((lent txt) q.p.vex) ?=(~ q.vex)) :: - q.p.vex :: - (fun p.u.q.vex) :: --