Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Set registry machine
Browse files Browse the repository at this point in the history
  • Loading branch information
Merle Breitkreuz committed May 31, 2019
1 parent 1a8cece commit b01706d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
33 changes: 30 additions & 3 deletions bin/rad-registry
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,28 @@
(import prelude/strings '[split-by] :unqualified)
(import prelude/validation :as 'validation)
(import prelude/machine :as 'machine)
(import prelude/io :as 'io)
(import prelude/io-utils :as 'io)

;; (import monadic/registry '[create-registry-machine!] :unqualified)
(def path!
(fn []
(string-append (io/base-path!) "/registry.rad")))

(def machine-name (fn [] "12D3KooWNdyJ1QpNy5RbBfjKEx1gPvRJ72tgYo1vs6jvXU8yuQN2"))
(def init-registry-file!
(fn []
(io/shell! (string-append "mkdir -p " (io/base-path!)) "")
(io/init-file-dict! (path!))))

(def machine-name
(fn []
(init-registry-file!)
(match (io/read-file-key! (path!) :registry)
:nothing (do
(put-str! "No registry set. Run `rad registry set <registry-id>`.")
(exit! 1))
[:just 'r] r
)))

(def valid-states ["open" "closed"])

Expand All @@ -35,7 +53,8 @@
rad registry new
rad registry [show | close | mark-read | mark-unread] <project-number>
rad registry all-read
rad init
rad registry init
rad registry set <registry-id>
rad registry help

list - Lists all projects
Expand All @@ -56,7 +75,8 @@
mark-read - Mark project as read
mark-unread - Mark project as unread
all-read - Mark all projects as read
init - Initialize a new register machine
init - Initialize a new registry machine
set - Set the registry that is used for the commands.
help - Print this help and exit
"))

Expand Down Expand Up @@ -139,12 +159,19 @@
(put-str! "=> Assembled rad registry machine")
(put-str! (string-append "=> registry id: " registry))))

(def set-registry!
(fn [id]
(init-registry-file!)
(io/write-file-key! (path!) :registry id)
(put-str! (string-append "=> Set registry machine to " id))))

(machine/catch-daemon!
(fn []
(match args
(/list-cmd 'options) (list (machine-name) options)
(/cmd-0 "new" help) (new-project (machine-name))
(/cmd-0 "init" help) (new-registry!)
(/cmd-1 "set" 'n help) (set-registry! n)
(/cmd-1 "close" 'n help) (whole-project-num "close" n (fn [n] (close-project n (machine-name))))
(/cmd-1 "show" 'n help) (whole-project-num "show" n (fn [n] (show-project! n (machine-name))))
(/cmd-1 "show-id" 'n help) (whole-project-num "show-id" n (fn [n] (show-project-id! n (machine-name))))
Expand Down
6 changes: 3 additions & 3 deletions rad/monadic/registry-remote.rad
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
(def validator/sub-project (validator/optional-keys project-keys))

(def validator/project-input
"An project should have all the required fields, be a signed input, etc."
"A project should have all the required fields, be a signed input, etc."
(validator/and
[;; NOTE that we don't check `validator/input` at this point, because some of
;; the data is fixed before validation.
Expand All @@ -101,7 +101,7 @@
[:project-number :modified-at :author :signature]))))

(def validator/project-edit-input
"An input to edit an project."
"An input to edit a project."
(validator/and
[validator/input
validator/time-modified
Expand Down Expand Up @@ -145,7 +145,7 @@
(<> old new))))

(def edit-project
"Modify some of the attributes of an project."
"Modify some of the attributes of a project."
(fn [i]
(validator/project-edit-input i)
(def i_ (delete :author (strip-input i)))
Expand Down

0 comments on commit b01706d

Please sign in to comment.