This commit is contained in:
parent
b47bff55af
commit
ad9ef045cb
@ -13,11 +13,10 @@ version = "1.0.0"
|
||||
# https://gleam.run/writing-gleam/gleam-toml/.
|
||||
|
||||
[dependencies]
|
||||
gleam_stdlib = "0.45.0"
|
||||
gleam_stdlib = ">= 0.50.0 and < 1.0.0"
|
||||
gleam_otp = ">= 0.15.0 and < 1.0.0"
|
||||
gleam_json = ">= 2.1.0 and < 3.0.0"
|
||||
simplifile = ">= 2.2.0 and < 3.0.0"
|
||||
decode = ">= 0.5.0 and < 1.0.0"
|
||||
glisten = ">= 7.0.0 and < 8.0.0"
|
||||
gleam_erlang = ">= 0.33.0 and < 1.0.0"
|
||||
spinner = ">= 1.3.0 and < 2.0.0"
|
||||
|
||||
@ -3,25 +3,25 @@
|
||||
|
||||
packages = [
|
||||
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
|
||||
{ name = "birl", version = "1.7.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "5C66647D62BCB11FE327E7A6024907C4A17954EF22865FE0940B54A852446D01" },
|
||||
{ name = "decode", version = "0.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "decode", source = "hex", outer_checksum = "05E14DC95A550BA51B8774485B04894B87A898C588B9B1C920104B110AED218B" },
|
||||
{ name = "birl", version = "1.8.0", build_tools = ["gleam"], requirements = ["gleam_regexp", "gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "2AC7BA26F998E3DFADDB657148BD5DDFE966958AD4D6D6957DD0D22E5B56C400" },
|
||||
{ name = "filepath", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "67A6D15FB39EEB69DD31F8C145BB5A421790581BD6AA14B33D64D5A55DBD6587" },
|
||||
{ name = "gleam_community_ansi", version = "1.4.2", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_regexp", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "479DEDC748D08B310C9FEB9C4CBEC46B95C874F7F4F2844304D6D20CA78A8BB5" },
|
||||
{ name = "gleam_community_colour", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "386CB9B01B33371538672EEA8A6375A0A0ADEF41F17C86DDCB81C92AD00DA610" },
|
||||
{ name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" },
|
||||
{ name = "gleam_http", version = "3.7.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "8A70D2F70BB7CFEB5DF048A2183FFBA91AF6D4CF5798504841744A16999E33D2" },
|
||||
{ name = "gleam_httpc", version = "4.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "76FEEC99473E568EBA34336A37CF3D54629ACE77712950DC9BB097B5FD664664" },
|
||||
{ name = "gleam_json", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "0A57FB5666E695FD2BEE74C0428A98B0FC11A395D2C7B4CDF5E22C5DD32C74C6" },
|
||||
{ name = "gleam_erlang", version = "0.34.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "0C38F2A128BAA0CEF17C3000BD2097EB80634E239CE31A86400C4416A5D0FDCC" },
|
||||
{ name = "gleam_http", version = "4.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "0A62451FC85B98062E0907659D92E6A89F5F3C0FBE4AB8046C99936BF6F91DBC" },
|
||||
{ name = "gleam_httpc", version = "4.1.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "1A38507AF26CACA145248733688703EADCB734EA971D4E34FB97B7613DECF132" },
|
||||
{ name = "gleam_json", version = "2.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "C55C5C2B318533A8072D221C5E06E5A75711C129E420DD1CE463342106012E5D" },
|
||||
{ name = "gleam_otp", version = "0.16.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "50DA1539FC8E8FA09924EB36A67A2BBB0AD6B27BCDED5A7EF627057CF69D035E" },
|
||||
{ name = "gleam_regexp", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "A3655FDD288571E90EE9C4009B719FEF59FA16AFCDF3952A76A125AF23CF1592" },
|
||||
{ name = "gleam_stdlib", version = "0.45.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "206FCE1A76974AECFC55AEBCD0217D59EDE4E408C016E2CFCCC8FF51278F186E" },
|
||||
{ name = "gleam_regexp", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_regexp", source = "hex", outer_checksum = "7F5E0C0BBEB3C58E57C9CB05FA9002F970C85AD4A63BA1E55CBCB35C15809179" },
|
||||
{ name = "gleam_stdlib", version = "0.54.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "723BA61A2BAE8D67406E59DD88CEA1B3C3F266FC8D70F64BE9FEC81B4505B927" },
|
||||
{ name = "gleam_yielder", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_yielder", source = "hex", outer_checksum = "8E4E4ECFA7982859F430C57F549200C7749823C106759F4A19A78AEA6687717A" },
|
||||
{ name = "glearray", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glearray", source = "hex", outer_checksum = "2CDF973B9ECE4A1AB8FBFB719AA37D9F3F1FF947B260C1B21ED5B608B52BC111" },
|
||||
{ name = "gleescript", version = "1.4.0", build_tools = ["gleam"], requirements = ["argv", "filepath", "gleam_erlang", "gleam_stdlib", "simplifile", "snag", "tom"], otp_app = "gleescript", source = "hex", outer_checksum = "8CDDD29F91064E69950A91A40061785F10275ADB70A0520075591F61A724C455" },
|
||||
{ name = "gleeunit", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "0E6C83834BA65EDCAAF4FE4FB94AC697D9262D83E6F58A750D63C9F6C8A9D9FF" },
|
||||
{ name = "glisten", version = "7.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib", "logging", "telemetry"], otp_app = "glisten", source = "hex", outer_checksum = "028C0882EAC7ABEDEFBE92CE4D1FEDADE95FA81B1B1AB099C4F91C133BEF2C42" },
|
||||
{ name = "glisten", version = "7.0.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib", "logging", "telemetry"], otp_app = "glisten", source = "hex", outer_checksum = "1A53CF9FB3231A93FF7F1BD519A43DC968C1722F126CDD278403A78725FC5189" },
|
||||
{ name = "logging", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "1098FBF10B54B44C2C7FDF0B01C1253CAFACDACABEFB4B0D027803246753E06D" },
|
||||
{ name = "mug", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "mug", source = "hex", outer_checksum = "C5F62A3FD753B823CE296ED1B223D4B2FF06E91170A7DE35A283D70BB74B700E" },
|
||||
{ name = "ranger", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "B8F3AFF23A3A5B5D9526B8D18E7C43A7DFD3902B151B97EC65397FE29192B695" },
|
||||
{ name = "ranger", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_yielder"], otp_app = "ranger", source = "hex", outer_checksum = "C8988E8F8CDBD3E7F4D8F2E663EF76490390899C2B2885A6432E942495B3E854" },
|
||||
{ name = "repeatedly", version = "2.1.2", build_tools = ["gleam"], requirements = [], otp_app = "repeatedly", source = "hex", outer_checksum = "93AE1938DDE0DC0F7034F32C1BF0D4E89ACEBA82198A1FE21F604E849DA5F589" },
|
||||
{ name = "simplifile", version = "2.2.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "0DFABEF7DC7A9E2FF4BB27B108034E60C81BEBFCB7AB816B9E7E18ED4503ACD8" },
|
||||
{ name = "snag", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "7E9F06390040EB5FAB392CE642771484136F2EC103A92AE11BA898C8167E6E17" },
|
||||
@ -32,13 +32,12 @@ packages = [
|
||||
|
||||
[requirements]
|
||||
birl = { version = ">= 1.7.1 and < 2.0.0" }
|
||||
decode = { version = ">= 0.5.0 and < 1.0.0" }
|
||||
gleam_community_ansi = { version = ">= 1.4.1 and < 2.0.0" }
|
||||
gleam_erlang = { version = ">= 0.33.0 and < 1.0.0" }
|
||||
gleam_httpc = { version = ">= 4.0.0 and < 5.0.0" }
|
||||
gleam_json = { version = ">= 2.1.0 and < 3.0.0" }
|
||||
gleam_otp = { version = ">= 0.15.0 and < 1.0.0" }
|
||||
gleam_stdlib = { version = "0.45.0" }
|
||||
gleam_stdlib = { version = ">= 0.50.0 and < 1.0.0" }
|
||||
gleescript = { version = ">= 1.4.0 and < 2.0.0" }
|
||||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
|
||||
glisten = { version = ">= 7.0.0 and < 8.0.0" }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import gleam/dynamic
|
||||
import gleam/dynamic/decode
|
||||
import gleam/io
|
||||
import gleam/json
|
||||
|
||||
@ -23,13 +23,13 @@ pub fn load(path) -> Config {
|
||||
}
|
||||
Ok(data) -> {
|
||||
let config_tree =
|
||||
dynamic.decode3(
|
||||
Config,
|
||||
dynamic.field("snapshots_path", dynamic.string),
|
||||
dynamic.field("port", dynamic.int),
|
||||
dynamic.field("forest", dynamic.list(dynamic.string)),
|
||||
)
|
||||
|> json.decode(data, _)
|
||||
{
|
||||
use snapshots_path <- decode.field("snapshots_path", decode.string)
|
||||
use port <- decode.field("port", decode.int)
|
||||
use forest <- decode.field("forest", decode.list(decode.string))
|
||||
decode.success(Config(snapshots_path:, port:, forest:))
|
||||
}
|
||||
|> json.parse(data, _)
|
||||
|
||||
case config_tree {
|
||||
Error(_) -> handle_malformed()
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
//// Functions to allow serialization from Tree to Json and back!
|
||||
|
||||
import decode/zero
|
||||
import gleam/dict
|
||||
import gleam/dynamic
|
||||
import gleam/dynamic/decode
|
||||
|
||||
import gleam/json.{bool, float, int, null, object, string}
|
||||
import gleam/list
|
||||
@ -51,7 +51,7 @@ fn leaf_to_json(tree: tree.Tree) -> json.Json {
|
||||
|
||||
/// Decodes a full tree (which root is tree.Root) from JSON
|
||||
pub fn deserialize(string) {
|
||||
case json.decode(string, zero.run(_, zero.dynamic)) {
|
||||
case json.parse(string, decode.dynamic) {
|
||||
Error(_) -> Error(DecodingError)
|
||||
Ok(data) -> data |> tree_decoder(True) |> Ok
|
||||
}
|
||||
@ -59,7 +59,7 @@ pub fn deserialize(string) {
|
||||
|
||||
/// Decodes a subtree (which root is NOT tree.Root) from JSON
|
||||
pub fn deserialize_sub(string) {
|
||||
case json.decode(string, zero.run(_, zero.dynamic)) {
|
||||
case json.parse(string, decode.dynamic) {
|
||||
Error(_) -> Error(DecodingError)
|
||||
Ok(data) -> data |> tree_decoder(False) |> Ok
|
||||
}
|
||||
@ -69,8 +69,8 @@ fn tree_decoder(data, root) {
|
||||
let _ = case dynamic.classify(data), root {
|
||||
"Dict", True -> {
|
||||
let children =
|
||||
zero.dict(zero.string, zero.dynamic)
|
||||
|> zero.run(data, _)
|
||||
decode.dict(decode.string, decode.dynamic)
|
||||
|> decode.run(data, _)
|
||||
|
||||
case children {
|
||||
Error(_) -> panic as "EncodingError"
|
||||
@ -83,8 +83,8 @@ fn tree_decoder(data, root) {
|
||||
|
||||
"Dict", False -> {
|
||||
let children =
|
||||
zero.dict(zero.string, zero.dynamic)
|
||||
|> zero.run(data, _)
|
||||
decode.dict(decode.string, decode.dynamic)
|
||||
|> decode.run(data, _)
|
||||
|
||||
case children {
|
||||
Error(_) -> panic as "EncodingError"
|
||||
@ -105,19 +105,19 @@ fn tree_decoder(data, root) {
|
||||
pub fn decode_leafdata(data) {
|
||||
case dynamic.classify(data) {
|
||||
"Int" -> {
|
||||
use value <- result.try(dynamic.int(data))
|
||||
use value <- result.try(decode.run(data, decode.int))
|
||||
Ok(tree.Int(value))
|
||||
}
|
||||
"Float" -> {
|
||||
use value <- result.try(dynamic.float(data))
|
||||
use value <- result.try(decode.run(data, decode.float))
|
||||
Ok(tree.Float(value))
|
||||
}
|
||||
"Bool" -> {
|
||||
use value <- result.try(dynamic.bool(data))
|
||||
use value <- result.try(decode.run(data, decode.bool))
|
||||
Ok(tree.Bool(value))
|
||||
}
|
||||
"String" -> {
|
||||
use value <- result.try(dynamic.string(data))
|
||||
use value <- result.try(decode.run(data, decode.string))
|
||||
Ok(tree.String(value))
|
||||
}
|
||||
_ -> Ok(tree.Null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user