Skip to content

Commit 6b5e7dd

Browse files
committed
Replace toml serializer with our own parser
1 parent f762ecc commit 6b5e7dd

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

rad.nimble

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ srcDir = "src"
99
bin = @["rad"]
1010

1111
requires "nim >= 2.3.1"
12-
requires "tomlSerialization >= 0.2.14"

src/packages.nim

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
# License, v. 2.0. If a copy of the MPL was not distributed with this
77
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
88

9-
import
10-
std/[algorithm, os, osproc, sequtils, strformat, strutils, tables, times],
11-
utils,
12-
toml_serialization
9+
import std/[algorithm, os, osproc, sequtils, strformat, strutils, tables, times], utils
1310

1411
const
1512
pkgCache* = "/var/cache/rad/pkg"
@@ -37,7 +34,40 @@ proc parseInfo*(name: string): Package =
3734
if not dirExists(path):
3835
abort(&"""{"name":8}{&"\{name\} not found":48}""")
3936

40-
Toml.loadFile(path / "info", Package)
37+
for line in (path / "info").lines:
38+
let line = line.strip()
39+
40+
if line.isEmptyOrWhitespace() or line.startsWith('#'):
41+
continue
42+
43+
if line.contains("= \"") or line.contains(" =\"") or '=' notin line:
44+
abort(&"""{"name":8}{&"wrong format":48}""")
45+
46+
let
47+
pair = line.split('=', 1)
48+
key = pair[0]
49+
var value = pair[1]
50+
51+
if not (value.startsWith('"') and value.endsWith('"')):
52+
abort(&"""{"name":8}{&"wrong format":48}""")
53+
54+
value = value.strip(chars = {'"'})
55+
56+
case key
57+
of "ver":
58+
result.ver = value
59+
of "url":
60+
result.url = value
61+
of "sum":
62+
result.sum = value
63+
of "bld":
64+
result.bld = value
65+
of "run":
66+
result.run = value
67+
of "opt":
68+
result.opt = value
69+
else:
70+
abort(&"""{"name":8}{&"wrong format":48}""")
4171

4272
proc printContent(idx: int, name, ver, cmd: string) =
4373
echo &"""{idx + 1:<8}{name:24}{ver:24}{cmd:8}""" & now().format("hh:mm tt")

0 commit comments

Comments
 (0)