all repos — min @ 808a2209d8a8177816193625376dcf503225cfda

A small but practical concatenative programming language.

Implemented update command.
h3rald h3rald@h3rald.com
Thu, 30 Nov 2023 11:58:38 +0100
commit

808a2209d8a8177816193625376dcf503225cfda

parent

148ab34a4fc89b119d7e538610f65949d369db8e

2 files changed, 70 insertions(+), 7 deletions(-)

jump to
M min.nimmin.nim

@@ -157,8 +157,9 @@ compile <file>.min Compile <file>.min.

eval <string> Evaluate <string> as a min program. help <symbol|sigil> Print the help contents related to <symbol|sigil>. init Sets up the current directory as a managed min module. - install [<module> <version>] Install the specified managed min module. - uninstall [<module> <version>] Uninstall the specified managed min module. + install [<module> <version>] Install the specified managed min module or all dependent modules. + uninstall [<module> <version>] Uninstall the specified managed min module or all dependent modules. + update [<module> <version>] Update the specified managed min module or all dependent modules. Options: -a, --asset-path Specify a directory containing the asset files to include in the compiled executable (if -c is set)

@@ -281,8 +282,14 @@ if args.len > 2:

version = args[2] executeMmmCmd(proc () = MMM.uninstall(name, version, GLOBAL)) elif file == "update": - logging.error "[update] Not implemented." - quit(100) + if args.len < 2: + executeMmmCmd(proc () = MMM.update()) + if args.len < 3: + logging.error "Module version not specified." + quit(11) + let name = args[1] + let version = args[2] + executeMmmCmd(proc () = MMM.update(name, version, GLOBAL)) elif file == "search": logging.error "[search] Not implemented." quit(100)
M minpkg/core/mmm.nimminpkg/core/mmm.nim

@@ -190,7 +190,7 @@ if not mmmJson.fileExists:

raiseError "No mmm.json file found in the current directory." let data = mmmJson.parseFile if not data.hasKey "deps": - raiseError "No 'deps' key present in the mmm.json file." + raiseError "No 'deps' key present in the mmm.json file in the current directory." for name, v in data["deps"].pairs: let version = v.getStr try:

@@ -200,7 +200,7 @@ warn getCurrentExceptionMsg()

continue except CatchableError: debug getCurrentExceptionMsg() - warn "Installation of '$#@$#' failed - Rolling back..." % [name, version] + warn "Installation of module $#@$# failed - Rolling back..." % [name, version] try: MMM.setup(false) MMM.uninstall(name, version)

@@ -211,7 +211,63 @@ warn "Rollback failed."

finally: raiseError "Installation failed." - +proc update*(MMM: var MinModuleManager, name, version: string, global = false) = + var dir: string + if global: + dir = MMM.globalDir / name / version + else: + dir = MMM.localDir / name / version + if not dir.dirExists(): + raiseError "Module '$#' (version: $#) is not installed." % [name, version] + # Read local mmm.json + let mmmJson = dir / "mmm.json" + if not mmmJson.fileExists: + raiseError "No mmm.json file found for managed module $#@$#" % [name, version] + var data: JsonNode + try: + data = mmmJson.parseFile + except CatchableError: + raiseError "Unable to parse mmm.json file for managed module $#@$#" % [name, version] + if not data.hasKey("method"): + raiseError "Installation method not specified for module '$#'" % [name] + let meth = data["method"].getStr + if meth != "git": + raiseError "Unable to install module '$#': Installation method '$#' is not supported" % [name, meth] + if not data.hasKey("url"): + raiseError "URL not specified for module '$#'" % [name] + let url = data["url"].getStr + let cmd = "git -C \"$#\" pull" % [dir.replace("\\", "/"), url, version] + debug cmd + notice "Updating module $#@$#..." % [name, version] + if not data.hasKey("deps"): + raiseError "Dependencies not specified for module '$#'" % [name] + var result = execShellCmd(cmd) + if (result == 0): + # Go to directory and install dependencies + dir.setCurrentDir() + MMM.setup(false) + if data["deps"].pairs.toSeq().len > 0: + notice "Updating dependencies..." + for depName, depVersion in data["deps"].pairs: + try: + MMM.update depName, depVersion.getStr, global + except CatchableError: + warn getCurrentExceptionMsg() + raiseError "Update of module '$#@$#' failed." % [name, version] +proc update*(MMM: var MinModuleManager) = + let mmmJson = getCurrentDir() / "mmm.json" + if not mmmJson.fileExists: + raiseError "No mmm.json file found in the current directory." + let data = mmmJson.parseFile + if not data.hasKey "deps": + raiseError "No 'deps' key present in the mmm.json file in the current directory." + for name, v in data["deps"].pairs: + let version = v.getStr + try: + MMM.update name, version + except CatchableError: + debug getCurrentExceptionMsg() + warn "Update of module '$#@$#' failed." % [name, version]