Skip to content

Add command for "list-outdated" #586

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/cls/IPM/Main.cls
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,15 @@ generate /my/path -export 00000,PacketName2,IgnorePacket2^00000,PacketName3,Igno
</example>
</command>

<command name="list-outdated" aliases="outdated">
<description>
Shows outdated modules and the latest version available in each repository.
</description>
<summary>
Shows outdated modules.
</summary>
</command>

</commands>
}

Expand Down Expand Up @@ -804,6 +813,8 @@ ClassMethod ShellInternal(pCommand As %String, Output pException As %Exception.A
Do ..Namespace(.tCommandInfo)
} ElseIf (tCommandInfo = "enable") {
Do ..EnableIPM(.tCommandInfo)
} ElseIf (tCommandInfo = "list-outdated") {
Do ..ListOutdated(.tCommandInfo)
}
} Catch pException {
If (pException.Code = $$$ERCTRLC) {
Expand Down Expand Up @@ -2867,6 +2878,62 @@ ClassMethod EnableIPM(ByRef pCommandInfo)
}
}

ClassMethod CanUpdate(modName As %String, semver As %IPM.General.SemanticVersion) As %Boolean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isc-shuliu Doesn't look like this method is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. I haven't gone to that point yet. My plan is to show if an outdated package can be updated to a particular version without violating dependency constraint. This PR is still a Work-In-Progress

{
Do ..GetListModules($Namespace, "", .list)
For i=1:1:list {
Set $ListBuild(otherMod, version) = list(i)
If (otherMod = modName) {
Continue
}
Set otherMod = ##class(%IPM.Storage.Module).NameOpen(otherMod)
// There is no need to recurse here
For i = 1:1:otherMod.Dependencies.Count() {
If (otherMod.Dependencies.GetAt(i).Name '= modName) {
Continue
}
#dim expresion As %IPM.General.SemanticVersionExpression
Set expression = otherMod.Dependencies.GetAt(i).Version
If 'expression.IsSatisfiedBy(semver) {
Return 0
}
}
}
Return 1
}

ClassMethod ListOutdated(ByRef pCommandInfo)
{
Do ..GetListModules($Namespace, "", .list)
Do ..GetUpstreamPackageVersions(.serverVersions)

For i=1:1:list {
Set $ListBuild(module, version) = list(i)
If $Data(serverVersions(module)) \ 10 = 0 {
Continue
}
Set semver = ##class(%IPM.General.SemanticVersion).FromString(version)
Set repo = ""
Set found = 0
For {
Set repo = $Order(serverVersions(module, repo), 1, remoteVersion)
If repo = "" {
Quit
}
Set remoteSemver = ##class(%IPM.General.SemanticVersion).FromString(remoteVersion)
// TODO use better comparison method
If 'remoteSemver.Follows(semver) {
Continue
}
If 'found {
Set found = 1
Write !, $$$FormattedLine($$$Green, module), " ", $$$FormattedLine($$$Blue, version)
}
Write " ", $$$FormattedLine($$$Red, $$$FormatText("%1:v%2", repo, remoteVersion))
}
}
}

/// Runs package manager commands in a way that is friendly to the OS-level shell.
/// Creates <var>pOutputLogFile</var> if it does not exist.
/// If it does, and <var>pAppendToLog</var> is true, appends to it; otherwise, deletes the file before outputting to it.
Expand Down