Skip to content

Commit

Permalink
Allow running offline without specified version (#166)
Browse files Browse the repository at this point in the history
* Allow running offline without specified version

Inform users about local fallback

* Read currently installed versions from Cache

* Prefer last version over first

It’s more likely to be the latest version

* Update CHANGELOG.md
  • Loading branch information
vknabel authored May 13, 2020
1 parent 4c606b5 commit 31e3984
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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
.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

0 comments on commit 31e3984

Please sign in to comment.