7
7
## TLDR
8
8
- come back later
9
9
10
- todos
11
- -----
12
- - cmd to parse arbitrarily, e.g. boat conf load ./some/dir
13
- - cmd to see current captains: e.g. boat conf list -> X, Y, Z
14
10
]##
15
11
16
12
from ../../../ bdd import tddError
@@ -31,15 +27,12 @@ import
31
27
var captainsLog* {.global .} = %* {} # # \
32
28
# # captains log is the world
33
29
34
- proc parseLocalManifest * (self: BoatConfig , path: string = " " ): bool =
35
- # # parse self.use to self.parsed
36
- # # prefer calling self.load or self.reload for validation
37
- let usePath = self.usePath path
38
-
39
- # self.parsed = self.parsed.retrieve usePath
30
+ proc parseManifest * (self: BoatConfig , path: string = " " , ft: FileType ): bool =
31
+ # # sets self.parsed to the parsed manifest
32
+ self.parsed = ft.retrieve self.usePath path
40
33
result = true
41
34
42
- proc localManifestIsValid * (self: BoatConfig , path: string = " " ): bool =
35
+ proc manifestIsValid * (self: BoatConfig , path: string = " " ): bool =
43
36
# # throws if manifest not found, cant be read, or errors during parsing
44
37
let usePath = self.usePath path
45
38
let pathInfo = usePath.getFileInfo
@@ -48,62 +41,53 @@ proc localManifestIsValid*(self: BoatConfig, path: string = ""): bool =
48
41
of pcFile, pcLinkToFile:
49
42
if fpUserRead notin pathInfo.permissions: raise filePermissionError
50
43
elif not usePath.endsWith manifestName: raise manifestNameError
51
- elif not self.parseLocalManifest usePath: raise configParseError
44
+ elif not self.parseManifest ( usePath, localManifest) : raise configParseError
52
45
else : true
53
46
of pcDir, pcLinkToDir:
54
47
# force directories to use their manifest
55
48
self.use = self.use / manifestName
56
- self.localManifestIsValid ()
49
+ self.manifestIsValid
57
50
58
51
proc save * (self: BoatConfig , path: string = " " ): bool =
59
52
# # serialize Self.parsed to disk @ boatConstants.cacheDir / <SELF.ID>.{manifestName}
60
53
# # updates captains manifest with stuffWeCached.self.use -> cache location
61
54
# should call fileManager.toDisk
62
55
result = true
63
56
64
- proc init * (self: BoatConfig , path: string = " " ): bool =
65
- let usePath = self.usePath path
57
+ proc init * (self: BoatConfig ): bool =
66
58
# starts with https?
67
59
# ends with manifestName?
68
- # save to boatConstants.tempDir / self.use
69
- # recurse self.reload path = temp location
60
+ # check FileManagerUtils.retrieve
61
+ # it should contain logic for loading remote manifests
70
62
# throw: urls must point to a manifest.nim.ini
71
- case usePath .startsWith " https"
63
+ case self.use .startsWith " https"
72
64
of true : raise tddError
73
65
else :
74
- try : doAssert self.localManifestIsValid (path) == true
66
+ try : doAssert self.manifestIsValid == true
75
67
except CatchableError :
76
68
debugEcho repr getCurrentException ()
77
69
raise fileLoadError
78
- if not self.save usePath : raise fileSaveDefect
70
+ if not self.save: raise fileSaveDefect
79
71
else : result = true
80
72
81
73
proc reload * (self: BoatConfig ): bool =
82
- # # reloads a configuration from disk
83
- # (fpath, T) = FileMananger.fromDisk(...)
84
- # self.parsedPath = fpath, self.parsed = T
74
+ # # reloads a configuration from captainsLog
85
75
raise tddError
86
76
87
77
proc load * (self: BoatConfig ): bool =
88
- # # (re)load a Configuration; safer than calling reload specifically
78
+ # # (re)load a Configuration
89
79
result =
90
- if captainsLogLoaded and self.parsedPath.len is Positive : self.reload ()
91
- else : self.init ()
80
+ # if self.use in captainsLog ? reload from captainslog
81
+ if 1 > 2 : raise tddError
82
+ else : self.init
92
83
93
84
proc loadCaptainsLog (): void =
94
85
# # loads the previous or initializes a new captains log
95
- if not captainsLogLoaded: echo " loading captains log"
96
- # captainsLogLoaded = true
97
- # let (fpath, prevCaptainsLog) = captainsLog.fromDisk(cacheDir / manifestName, JsonNode, false)
98
- # captainsLog = prevCaptainsLog
86
+ captainsLogLoaded = true
87
+ # try to retrieve the prev captainslog from cachDir
88
+ # else initialize an empty captainslog
99
89
100
90
# always load the captainsLog into ram
101
91
if not captainsLogLoaded: loadCaptainsLog ()
102
92
103
-
104
- # consumers can retrieve the parsed Config and path on disk
105
- # but only internal functions should be able to set it
106
- export
107
- boatConfigType.BoatConfig ,
108
- parsed,
109
- parsedPath
93
+ export boatConfigType
0 commit comments