Skip to content
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

Add outdated command #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
19 changes: 19 additions & 0 deletions Sources/MintCLI/Commands/OutdatedCommand.swift
Original file line number Diff line number Diff line change
@@ -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()
}
}
1 change: 1 addition & 0 deletions Sources/MintCLI/MintCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MintCLI {
ListCommand(mint: mint),
BootstrapCommand(mint: mint),
WhichCommand(mint: mint),
OutdatedCommand(mint: mint),
])
}

Expand Down
40 changes: 40 additions & 0 deletions Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down