-
Notifications
You must be signed in to change notification settings - Fork 27
feat(cli): add -outdated modifier in list command #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
2029db0
42d3684
265414b
c71fcf3
269c97b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -526,6 +526,9 @@ reinstall -env /path/to/env1.json;/path/to/env2.json example-package | |
| <example description="Shows all installed Python packages."> | ||
| list -python | ||
| </example> | ||
| <example description="Lists all installed modules with available updates in the registry."> | ||
| list -outdated | ||
| </example> | ||
|
|
||
| <!-- Parameters --> | ||
| <parameter name="searchString" description="Search string, * can be used." /> | ||
|
|
@@ -538,6 +541,7 @@ reinstall -env /path/to/env1.json;/path/to/env2.json example-package | |
| <modifier name="showupstream" aliases="su" description="If specified, show the latest version for each module in configured repos if it's different than the local version." /> | ||
| <modifier name="repository" aliases="repo" value="true" description="If specified, only show modules installed that belong to the provided repository." /> | ||
| <modifier name="python" aliases="py" description="If specified, lists installed Embedded Python libraries instead of IPM modules." /> | ||
| <modifier name="outdated" aliases="o" description="Lists installed modules that have available updates in the registry." /> | ||
| </command> | ||
|
|
||
| <command name="list-dependents" aliases="dependents"> | ||
|
|
@@ -2757,6 +2761,12 @@ ClassMethod ListInstalled(ByRef pCommandInfo) [ Private ] | |
| do ..DisplayModules(.list,,,, .tModifiers) | ||
| quit | ||
| } | ||
| if $data(pCommandInfo("modifiers","outdated")) { | ||
| merge tModifiers = pCommandInfo("modifiers") | ||
| do ..GetOutdatedModulesList(.list) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice for the |
||
| do ..DisplayModules(.list,,,, .tModifiers) | ||
| quit | ||
| } | ||
| if (''$data(pCommandInfo("modifiers","tree"))) { | ||
| // Show tree of dependencies as well. | ||
| // Modules that are dependencies for no other are shown at the top level. | ||
|
|
@@ -2821,8 +2831,7 @@ ClassMethod GetListModule( | |
| { | ||
| new $namespace | ||
| set $namespace=ns | ||
| set tRes = ##class(%SQL.Statement).%ExecDirect(, | ||
| "select * from %IPM_Storage.ModuleItem") | ||
| set tRes = ##class(%SQL.Statement).%ExecDirect(, "select * from %IPM_Storage.ModuleItem") | ||
| $$$ThrowSQLIfError(tRes.%SQLCODE,tRes.%Message) | ||
| set in="" | ||
| while tRes.%Next(.tSC) { | ||
|
|
@@ -4171,6 +4180,30 @@ ClassMethod Update(ByRef pCommandInfo) | |
| } | ||
| } | ||
|
|
||
| ClassMethod GetOutdatedModulesList(Output List) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also check if the new versions satisfy the existing version constraints? If not, it should. For example, if we have module-a that depends on module-b ^1.3.0, and the available versions of module-b are 1.3.0 and 2.0.0, then
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @isc-dchui So, in this scenario,
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok! Let's add a test to make sure this works! (Also you have some failing tests)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. Thank you!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @isc-dchui Thanks for pointing that out. Since the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @isc-dchui
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The simplest would probably be adding the test modules to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the suggestion. Setting up a filesystem repository is a new configuration for me. Could you please point me toward the official documentation or a guide for this? That would be very helpful for my setup.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't much, but here's an example in the wiki: |
||
| { | ||
| do ..GetListModules($namespace,,.installedModules) | ||
| do ..GetUpstreamPackageVersions(.serverModuleVersions) | ||
| set width = 0 | ||
| for i=1:1:installedModules { | ||
| set moduleInfo = installedModules(i) | ||
| set moduleName = $listget(moduleInfo) | ||
| continue:moduleName="zpm" | ||
| set currentVersion = $listget(moduleInfo,2) | ||
| if $data(serverModuleVersions(moduleName)) { | ||
| set reg = $order(serverModuleVersions(moduleName,""),1,versionString) | ||
| if currentVersion'=versionString { | ||
| set currentwidth = $length(moduleName) | ||
| set List($increment(List)) = $listbuild(moduleName,$$$FormattedLine($$$Red, currentVersion)_" "_$$$FormattedLine($$$Green,versionString)) | ||
| if width<currentwidth { | ||
| set width = currentwidth | ||
| } | ||
| } | ||
| } | ||
| } | ||
| set List("width") = width | ||
| } | ||
|
|
||
| ClassMethod GetPythonInstalledLibs(Output list) | ||
| { | ||
| set target = ##class(%File).NormalizeDirectory("python", $system.Util.ManagerDirectory()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -352,4 +352,43 @@ Method TestUninstallWithoutModuleName() | |
| do $$$AssertNotTrue(exists, "Module removed successfully.") | ||
| } | ||
|
|
||
| /// Validates that the '-outdated' modifier correctly identifies and displays modules with newer registry versions | ||
| Method TestListOutdatedModules() | ||
| { | ||
| set moduleName = "irisjwt" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably add a test with more than one module and one with dependencies. |
||
| if $isobject(##class(%IPM.Storage.Module).NameOpen(moduleName)) { | ||
| do $$$LogMessage(moduleName_" already exist. So uninstalling the module") | ||
| do ..RunCommand("uninstall "_moduleName) | ||
| } | ||
|
|
||
| set status = ..RunCommand("install "_moduleName_" 1.0.0") | ||
| do $$$AssertStatusOK(status, moduleName_" installed at version 1.0.0") | ||
| do ##class(%IPM.Main).GetOutdatedModulesList(.list) | ||
|
|
||
| set found = 0 | ||
| for i=1:1:list { | ||
| set moduleInfo = list(i) | ||
| set currentModuleName = $listget(moduleInfo, 1) | ||
| set versionString = $listget(moduleInfo, 2) | ||
|
|
||
| // Scrub ANSI color codes | ||
| set matcher = ##class(%Regex.Matcher).%New("\x1b\[[0-9;]*m", versionString) | ||
| set cleanString = matcher.ReplaceAll("") | ||
|
|
||
| set cleanString = $zstrip(cleanString, "<>W") | ||
| set currentVersion = $piece(cleanString, " ", 1) | ||
| set serverVersion = $piece(cleanString, " ", 2) | ||
| if (moduleName = currentModuleName) { | ||
| set found = 1 | ||
| } | ||
| if currentVersion'=serverVersion { | ||
| do $$$AssertNotEquals(currentVersion, serverVersion, "Version mismatch detected for "_moduleName) | ||
| do $$$LogMessage(currentVersion_" "_serverVersion) | ||
| do $$$LogMessage("Currently installed "_currentModuleName_" (local:"_currentVersion_") has a newer version available (server:"_serverVersion_")") | ||
| } | ||
| } | ||
| do $$$AssertTrue(found, "The module "_moduleName_" was found in the outdated list") | ||
| do ..RunCommand("list -o") | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.