aboutsummaryrefslogtreecommitdiff
path: root/licentia/source/program/licentia.lux
blob: 1f4d30fe6d06f15f570d7325471fb840cf2e8b36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
... 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/

(.using
 [library
  [lux (.except)
   [ffi (.only import)]
   [program (.only program:)]
   ["[0]" debug]
   [abstract
    [monad (.only do)]]
   [control
    [remember (.only to_do)]
    ["[0]" io (.only IO) (.open: "[1]#[0]" monad)]
    ["[0]" maybe]
    ["[0]" try (.only Try)]
    ["[0]" parser
     ["<[0]>" cli]
     ["<[0]>" json]]
    [security
     ["!" capability]]]
   [data
    ["[0]" text
     ["%" format (.only format)]
     [encoding
      ["[0]" utf8]]]
    [format
     ["[0]" json]]]
   [world
    ["[0]" file]]]]
 ["[0]" /
  ["[1][0]" input]
  ["[1][0]" output]])

(with_expansions [<expiry> "2022-04-01"]
  (to_do <expiry> "Create a short notice to add as a comment to each file in the _.work"))

(import java/lang/String
  "[1]::[0]"
  (trim [] java/lang/String))

(def: default_output_file
  "LICENSE.txt")

(def: (success_message output)
  (-> file.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
    [?done (is (IO (Try Any))
               (do (try.with io.monad)
                 [blob (at file.default read input)
                  document (io#wrap (do [! try.monad]
                                      [raw_json (at utf8.codec decoded blob)
                                       json (|> raw_json
                                                java/lang/String::trim
                                                (at json.codec decoded))]
                                      (|> json
                                          (<json>.result /input.license)
                                          (at ! each /output.license))))]
                 (at file.default write (at utf8.codec encoded document) output)))]
    (wrap (debug.log! (case ?done
                        {try.#Success _}
                        (success_message output)

                        {try.#Failure message}
                        message)))))