-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* break everything to match ADRs * rework round 1: manifest subtype and tests fixed * rework: boatConfig + tests * filemanager + tests * rework bdd for easier inner tests * filemanager current implementation tests * filemanager current implementation + tests
- Loading branch information
Showing
40 changed files
with
1,378 additions
and
826 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
## .. include:: ./readme.rst | ||
|
||
import boat/private/boatConfig | ||
import boat/manifest | ||
|
||
proc boat*: void = echo "All HANDS! cat o'nine tails! blue peter! OMG... landlubber" | ||
|
||
when isMainModule: | ||
let fake = BoatConfig[Config](use: "fake config") | ||
let fake = Manifest(use: "fake config") | ||
debugEcho fake.use |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# import std/[ | ||
# json, | ||
# os, | ||
# ] | ||
|
||
from ../../bdd import tddError | ||
|
||
import std/[os, strutils] | ||
|
||
from private/captainsLogUtils import logAction, Action | ||
|
||
import private/[ | ||
boatConfig, | ||
boatErrors, | ||
fileManager | ||
] | ||
|
||
const manifestName* = "manifest.nim.ini" ## \ | ||
## the captains manifest must be named manifest.nim.ini | ||
|
||
type Manifest* = ref object of BoatConfig | ||
parsed*: Config ## \ | ||
## the parsed configuration | ||
|
||
method parse*(self: Manifest, path: string = ""): bool = | ||
## parses a local BoatConfig | ||
self.parsed = retrieve[Config](self.parsed, self.usePath path) | ||
result = true | ||
|
||
method isValid*(self: Manifest): bool = | ||
## throws if self.use not found, cant be read, or errors during parsing | ||
let pathInfo = self.use.getFileInfo | ||
|
||
result = case pathInfo.kind | ||
of pcFile, pcLinkToFile: | ||
if fpUserRead notin pathInfo.permissions: raise filePermissionError | ||
elif not self.use.endsWith manifestName: raise manifestNameError | ||
elif not self.parse: raise configParseError | ||
else: true | ||
of pcDir, pcLinkToDir: | ||
# force directories to use their manifest | ||
self.use = self.use / manifestName | ||
self.isValid | ||
|
||
|
||
method save*(self: Manifest): bool = | ||
## caches BoatConfig to disk (based on manifest dir) and updates CaptainsLog with path | ||
let fpath = waitFor toDisk[Config](self.parsed, self.use.pathDir) | ||
BoatConfigSave.logAction fpath | ||
|
||
|
||
method reload*(self: Manifest): bool = | ||
## reloads a configuration from CaptainsLog | ||
raise tddError | ||
|
||
method load*(self: Manifest): bool = | ||
## (re)load a Configuration | ||
result = | ||
# if self.use in CaptainsLog ? reload from CaptainsLog | ||
if 1 > 2: raise tddError | ||
else: self.init | ||
|
||
method init*(self: Manifest): bool = | ||
# starts with https? | ||
# ends with manifestName? | ||
# check FileManagerUtils.retrieve | ||
# it should contain logic for loading remote manifests | ||
# throw: urls must point to a manifest.nim.ini | ||
result = case self.use.startsWith "https" | ||
of true: raise tddError | ||
else: | ||
try: | ||
if self.isValid and self.save: true | ||
else: raise fileSaveDefect | ||
except CatchableError: | ||
debugEcho repr getCurrentException() | ||
raise fileLoadDefect | ||
|
||
when isMainModule: | ||
debugEcho repr Manifest(use: "xyz") | ||
debugEcho repr Manifest(use: "xyz").typeof |
Oops, something went wrong.