From 9afa890997363a0101c158f5b044293f7449d6df Mon Sep 17 00:00:00 2001 From: cgi Date: Thu, 12 May 2022 20:22:19 +0200 Subject: [PATCH 1/2] Add outdated command --- README.md | 1 + .../MintCLI/Commands/OutdatedCommand.swift | 19 +++++++++ Sources/MintCLI/MintCLI.swift | 1 + Sources/MintKit/Mint.swift | 40 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 Sources/MintCLI/Commands/OutdatedCommand.swift diff --git a/README.md b/README.md index e5edf0a..2a0998f 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ Run `mint help` to see usage instructions. - **which**: Print the path to an installed package executable. - **uninstall**: Uninstalls a package by name. - **bootstrap**: Installs all the packages in your [Mintfile](#mintfile), by default, without linking them globally +- **outdated**: List all in your [Mintfile](#mintfile), by default, installed and linked packages that are outdated. **Package reference** diff --git a/Sources/MintCLI/Commands/OutdatedCommand.swift b/Sources/MintCLI/Commands/OutdatedCommand.swift new file mode 100644 index 0000000..1fddb4d --- /dev/null +++ b/Sources/MintCLI/Commands/OutdatedCommand.swift @@ -0,0 +1,19 @@ + +import Foundation +import MintKit +import PathKit +import SwiftCLI + +class OutdatedCommand: MintfileCommand { + + init(mint: Mint) { + super.init(mint: mint, + name: "outdated", + description: "List all the currently installed and linked packages that are outdated.") + } + + override func execute() throws { + try super.execute() + try mint.outdated() + } +} diff --git a/Sources/MintCLI/MintCLI.swift b/Sources/MintCLI/MintCLI.swift index a163c0e..2b06150 100644 --- a/Sources/MintCLI/MintCLI.swift +++ b/Sources/MintCLI/MintCLI.swift @@ -32,6 +32,7 @@ public class MintCLI { ListCommand(mint: mint), BootstrapCommand(mint: mint), WhichCommand(mint: mint), + OutdatedCommand(mint: mint), ]) } diff --git a/Sources/MintKit/Mint.swift b/Sources/MintKit/Mint.swift index 4a7ee55..1ce9c13 100644 --- a/Sources/MintKit/Mint.swift +++ b/Sources/MintKit/Mint.swift @@ -497,6 +497,46 @@ public class Mint { } } + public func outdated() throws { + + let mintFile = try Mintfile(path: mintFilePath) + + guard !mintFile.packages.isEmpty else { + standardOut <<< "🌱 Mintfile is empty" + return + } + + let packageCount = "\(mintFile.packages.count) \(mintFile.packages.count == 1 ? "package" : "packages")" + + if verbose { + output("Found \(packageCount) in \(mintFilePath.string)") + } + + var hasUpdates = false + for package in mintFile.packages { + + let tagOutput = try Task.capture(bash: "git ls-remote --tags --refs \(package.gitPath)") + let versions = tagOutput.stdout + .split(separator: "\n") + .map { String($0.split(separator: "\t").last!.split(separator: "/").last!) } + .compactMap { Version($0) } + .sorted() + + if let latestVersion = versions.last, + let packageVersion = Version(package.version) { + + if packageVersion < latestVersion { + hasUpdates = true + output("\(package.name) is outdated: \(packageVersion.description) -> \(latestVersion.description)".yellow) + } + } + } + + if !hasUpdates { + output("\(packageCount) up to date".green) + } + } + public func uninstall(name: String) throws { // find packages From dce3976d9f0298700ff03f1f24a9eada4adcb0e9 Mon Sep 17 00:00:00 2001 From: Yonas Kolb Date: Wed, 4 Jun 2025 11:06:14 +0100 Subject: [PATCH 2/2] update docs --- README.md | 2 +- Sources/MintCLI/Commands/OutdatedCommand.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ac378f..4b29c85 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Run `mint help` to see usage instructions. - **which**: Print the path to an installed package executable. - **uninstall**: Uninstalls a package by name. - **bootstrap**: Installs all the packages in your [Mintfile](#mintfile), by default, without linking them globally -- **outdated**: List all in your [Mintfile](#mintfile), by default, installed and linked packages that are outdated. +- **outdated**: Lists the outdated packages in your [Mintfile](#mintfile) **Package reference** diff --git a/Sources/MintCLI/Commands/OutdatedCommand.swift b/Sources/MintCLI/Commands/OutdatedCommand.swift index 1fddb4d..96a0af0 100644 --- a/Sources/MintCLI/Commands/OutdatedCommand.swift +++ b/Sources/MintCLI/Commands/OutdatedCommand.swift @@ -9,7 +9,7 @@ class OutdatedCommand: MintfileCommand { init(mint: Mint) { super.init(mint: mint, name: "outdated", - description: "List all the currently installed and linked packages that are outdated.") + description: "List all the outdated packages in your Mintfile") } override func execute() throws {