all repos — min @ f87a2f95e002ab1eade089ff8e3183ad032b718a

A small but practical concatenative programming language.

mmm: added support for name@version syntax for install/uninstall/update.
h3rald h3rald@h3rald.com
Mon, 29 Jan 2024 13:38:09 +0100
commit

f87a2f95e002ab1eade089ff8e3183ad032b718a

parent

8b1d043b4a7ebc5ab502ff5c17b7226cc20f0f96

3 files changed, 32 insertions(+), 10 deletions(-)

jump to
M min.nimmin.nim

@@ -269,26 +269,24 @@ executeMmmCmd(proc () = MMM.init())

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

@@ -131,6 +131,14 @@ data["deps"].delete(name)

mmmJson.writeFile(data.pretty) notice "Uninstall complete." +proc uninstall*(MMM: var MinModuleManager, nameAndVersion: string, global = false) = + let parts = nameAndVersion.split("@") + if parts.len != 2: + raiseError "Invalid module name and version: $#. Expected: <module-name>@<module-version>" % [nameAndVersion] + let name = parts[0] + let version = parts[1] + MMM.uninstall name, version, global + proc uninstall*(MMM: var MinModuleManager) = let pwd = getCurrentDir() if not fileExists(pwd / "mmm.json"):

@@ -205,6 +213,14 @@ warn "Rollback failed."

finally: raiseError "Installation failed." +proc install*(MMM: var MinModuleManager, nameAndVersion: string, global = false) = + let parts = nameAndVersion.split("@") + if parts.len != 2: + raiseError "Invalid module name and version: $#. Expected: <module-name>@<module-version>" % [nameAndVersion] + let name = parts[0] + let version = parts[1] + MMM.install name, version, global + proc install*(MMM: var MinModuleManager) = let mmmJson = getCurrentDir() / "mmm.json" if not mmmJson.fileExists:

@@ -275,6 +291,14 @@ MMM.update depName, depVersion.getStr, global

except CatchableError: warn getCurrentExceptionMsg() raiseError "Update of module '$#@$#' failed." % [name, version] + +proc update*(MMM: var MinModuleManager, nameAndVersion: string, global = false) = + let parts = nameAndVersion.split("@") + if parts.len != 2: + raiseError "Invalid module name and version: $#. Expected: <module-name>@<module-version>" % [nameAndVersion] + let name = parts[0] + let version = parts[1] + MMM.update name, version, global proc update*(MMM: var MinModuleManager) = let mmmJson = getCurrentDir() / "mmm.json"
M site/contents/learn-mmm.mdsite/contents/learn-mmm.md

@@ -66,7 +66,7 @@ If no name and no version are specified, all dependencies of the current managed module (and their dependencies) will be updated.

### min list -List all the installed dependencies of tbe current module, and their dependencies, recursively. +List all the installed dependencies of the current module, and their dependencies, recursively. ### min search [arg1 arg2 ... argN]