aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/world/file.lux28
-rw-r--r--stdlib/source/program/licentia.lux42
2 files changed, 38 insertions, 32 deletions
diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux
index b909578d8..0592d41af 100644
--- a/stdlib/source/lux/world/file.lux
+++ b/stdlib/source/lux/world/file.lux
@@ -144,20 +144,20 @@
(def: separator (:: system separator)))))
-(def: #export (un-nest System<!> file)
+(def: #export (un-nest system file)
(All [!] (-> (System !) Path (Maybe [Path Text])))
- (case (text.last-index-of (:: System<!> separator) file)
+ (case (text.last-index-of (:: system separator) file)
#.None
#.None
(#.Some last-separator)
(let [[parent temp] (maybe.assume (text.split last-separator file))
- [_ child] (maybe.assume (text.split (text.size (:: System<!> separator)) temp))]
+ [_ child] (maybe.assume (text.split (text.size (:: system separator)) temp))]
(#.Some [parent child]))))
-(def: #export (nest System<!> [parent child])
+(def: #export (nest system [parent child])
(All [!] (-> (System !) [Path Text] Path))
- (format parent (:: System<!> separator) child))
+ (format parent (:: system separator) child))
(do-template [<name>]
[(exception: #export (<name> {file Path})
@@ -368,34 +368,34 @@
}))
(do-template [<get> <signature> <create> <find> <exception>]
- [(def: #export (<get> Monad<!> System<!> path)
+ [(def: #export (<get> monad system path)
(All [!] (-> (Monad !) (System !) Path (! (Error (<signature> !)))))
- (do Monad<!>
- [outcome (!.use (:: System<!> <create>) path)]
+ (do monad
+ [outcome (!.use (:: system <create>) path)]
(case outcome
(#error.Success file)
(wrap (#error.Success file))
(#error.Failure error)
(if (ex.match? <exception> error)
- (!.use (:: System<!> <find>) path)
+ (!.use (:: system <find>) path)
(wrap (#error.Failure error))))))]
[get-file File create-file file ..cannot-create-file]
[get-directory Directory create-directory directory ..cannot-create-directory]
)
-(def: #export (exists? Monad<!> System<!> path)
+(def: #export (exists? monad system path)
(All [!] (-> (Monad !) (System !) Path (! Bit)))
- (do Monad<!>
- [?file (!.use (:: System<!> file) path)]
+ (do monad
+ [?file (!.use (:: system file) path)]
(case ?file
(#error.Success file)
(wrap true)
(#error.Failure _)
- (do Monad<!>
- [?directory (!.use (:: System<!> directory) path)]
+ (do monad
+ [?directory (!.use (:: system directory) path)]
(case ?directory
(#error.Success directory)
(wrap true)
diff --git a/stdlib/source/program/licentia.lux b/stdlib/source/program/licentia.lux
index 479af7793..3300c380d 100644
--- a/stdlib/source/program/licentia.lux
+++ b/stdlib/source/program/licentia.lux
@@ -16,19 +16,21 @@
[control
[remember (#+ to-do)]
[monad (#+ do)]
- ["." parser]]
+ ["." parser]
+ [security
+ ["!" capability]]]
[data
["." maybe]
- ["." error]
+ ["." error (#+ Error)]
["." text
format
["." encoding]]
[format
["." json]]]
["." cli (#+ program:)]
- ["." io ("#/." monad)]
+ ["." io (#+ IO) ("#/." monad)]
[world
- ["." file (#+ File)]]
+ ["." file (#+ Path File)]]
[host (#+ import:)]]
[/
["/." input]
@@ -44,28 +46,32 @@
(def: default-output-file "LICENSE")
(def: (success-message output)
- (-> File Text)
+ (-> Path Text)
(format "Your license has been made!" text.new-line
"Check the file " output "."))
(program: [{input (cli.named "--input" cli.any)}
{output (parser.default ..default-output-file
(cli.named "--output" cli.any))}]
- (do io.Monad<IO>
- [?done (do io.Monad<Process>
- [blob (:: file.JVM@System read input)
- document (io/wrap (do error.Monad<Error>
- [raw-json (encoding.from-utf8 blob)
- json (|> raw-json
- (:coerce java/lang/String)
- java/lang/String::trim
- (:: json.Codec<Text,JSON> decode))
- license (json.run json /input.license)]
- (wrap (/output.license license))))]
- (:: file.JVM@System write (encoding.to-utf8 document) output))]
+ (do io.monad
+ [?done (: (IO (Error Any))
+ (do (error.with-error io.monad)
+ [file (!.use (:: file.system file) input)
+ blob (!.use (:: file content) [])
+ document (io/wrap (do error.monad
+ [raw-json (encoding.from-utf8 blob)
+ json (|> raw-json
+ (:coerce java/lang/String)
+ java/lang/String::trim
+ (:: json.codec decode))
+ license (json.run json /input.license)]
+ (wrap (/output.license license))))
+ output-file (: (IO (Error (File IO)))
+ (file.get-file io.monad file.system output))]
+ (!.use (:: output-file over-write) (encoding.to-utf8 document))))]
(case ?done
(#error.Success _)
(wrap (log! (success-message output)))
- (#error.Error message)
+ (#error.Failure message)
(wrap (log! message)))))