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

Allow running offline without specified version #166

Merged
merged 4 commits into from
May 13, 2020
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Master

#### Added
- Running offline without specified version [#164](https://github.com/yonaskolb/Mint/issues/164) [#166](https://github.com/yonaskolb/Mint/pull/166) @vknabel

## 0.14.2

#### Changed
Expand Down
16 changes: 15 additions & 1 deletion Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import PathKit
import Rainbow
import SwiftCLI
import Version

public class Mint {

Expand Down Expand Up @@ -172,7 +173,20 @@ public class Mint {
}
}
} catch {
throw MintError.repoNotFound(package.gitPath)
let metadata = try readMetadata()
let linkedExecutables = getLinkedExecutables()
let cache = try Cache(path: packagesPath, metadata: metadata, linkedExecutables: linkedExecutables)

guard let installedVersions = cache.packages
.first(where: { $0.gitRepo == package.repo })?
.versionDirs.map({ $0.version }),
let fallbackVersion = installedVersions.last else {
throw MintError.repoNotFound(package.gitPath)
}
package.version = installedVersions
vknabel marked this conversation as resolved.
Show resolved Hide resolved
.compactMap(Version.init)
.max()?.description ?? fallbackVersion
errorOutput( "Failed to find latest version online. Falling back to local version \(package.version)")
}
return true
} else {
Expand Down