aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/licentia.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-02-05 20:30:13 -0400
committerEduardo Julian2019-02-05 20:30:13 -0400
commit60430ee6dfffbeb220a3e8fee7336d54313467bc (patch)
treee00b48c2af5354392f514347547340f67f71e708 /stdlib/source/program/licentia.lux
parentc542e618266c2f321704bef381b14213c30cc2e0 (diff)
Folded license-making program (legislator) into the Lux project proper (as licentia).
Diffstat (limited to '')
-rw-r--r--stdlib/source/program/licentia.lux66
1 files changed, 66 insertions, 0 deletions
diff --git a/stdlib/source/program/licentia.lux b/stdlib/source/program/licentia.lux
new file mode 100644
index 000000000..29ecc7eab
--- /dev/null
+++ b/stdlib/source/program/licentia.lux
@@ -0,0 +1,66 @@
+## The licenses produced by this program are inspired by:
+## Apache License (Version 2.0): https://www.apache.org/licenses/LICENSE-2.0
+## Mozilla Public License (Version 2.0): https://www.mozilla.org/en-US/MPL/2.0/
+## MIT/Expat License: https://opensource.org/licenses/MIT
+## BSD licenses: https://en.wikipedia.org/wiki/BSD_licenses
+## Commons Clause: https://commonsclause.com/
+## Reciprocal Public License 1.5 (RPL-1.5): https://opensource.org/licenses/RPL-1.5
+## The Parity Public License: https://licensezero.com/licenses/parity
+## The Charity Public License: https://licensezero.com/licenses/charity
+## Lerna black-list: https://github.com/lerna/lerna/pull/1616
+## Common Public Attribution License Version 1.0 (CPAL-1.0): https://opensource.org/licenses/CPAL-1.0
+## Eclipse Public License v2.0: https://www.eclipse.org/legal/epl-2.0/
+
+(.module:
+ [lux #*
+ [control
+ [monad (#+ do)]
+ ["." parser]]
+ [data
+ ["." maybe]
+ ["." error]
+ ["." text
+ format
+ ["." encoding]]
+ [format
+ ["." json]]]
+ ["." cli (#+ program:)]
+ ["." io ("io/." Monad<IO>)]
+ [world
+ ["." file (#+ File)]]
+ [host (#+ import:)]]
+ [/
+ ["/." input]
+ ["/." output]])
+
+(import: #long java/lang/String
+ (trim [] String))
+
+(def: default-output-file "LICENSE")
+
+(def: (success-message output)
+ (-> File 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))]
+ (case ?done
+ (#error.Success _)
+ (wrap (log! (success-message output)))
+
+ (#error.Error message)
+ (wrap (log! message)))))