Skip to content

Add minor code improvements #279

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

Open
wants to merge 5 commits 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
6 changes: 3 additions & 3 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
swift: ["5.9.0"]
swift: ["6.0.2"]
steps:
- uses: actions/checkout@v2
- uses: swift-actions/setup-swift@v1
- uses: actions/checkout@v4
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- name: Resolve
Expand Down
7 changes: 2 additions & 5 deletions Sources/MintCLI/Commands/BootstrapCommand.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

import Foundation
import MintKit
import PathKit
import SwiftCLI

class BootstrapCommand: MintfileCommand {
final class BootstrapCommand: MintfileCommand {

@Key("-o", "--overwrite", description: "Automatically overwrite a symlinked executable that is not installed by mint without asking. Either (y/n)")
var overwrite: Bool?
private var overwrite: Bool?

init(mint: Mint) {
super.init(mint: mint,
Expand Down
12 changes: 6 additions & 6 deletions Sources/MintCLI/Commands/InstallCommand.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Foundation
import MintKit
import SwiftCLI

class InstallCommand: PackageCommand {
final class InstallCommand: PackageCommand {

@Param var executable: String?
@Param
private var executable: String?

@Flag("-n", "--no-link", description: "Whether to prevent global linkage")
var noLink: Bool
private var noLink: Bool

@Flag("-f", "--force", description: "Force a reinstall even if the package is already installed")
var force: Bool
private var force: Bool

@Key("-o", "--overwrite", description: "Automatically overwrite a symlinked executable that is not installed by mint without asking. Either (y/n)")
var overwrite: Bool?
private var overwrite: Bool?

init(mint: Mint) {
super.init(mint: mint,
Expand Down
3 changes: 1 addition & 2 deletions Sources/MintCLI/Commands/ListCommand.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation
import MintKit

class ListCommand: MintCommand {
final class ListCommand: MintCommand {

init(mint: Mint) {
super.init(mint: mint,
Expand Down
2 changes: 0 additions & 2 deletions Sources/MintCLI/Commands/MintCommand.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Foundation
import MintKit
import PathKit
import SwiftCLI

class MintCommand: Command {
Expand Down
7 changes: 2 additions & 5 deletions Sources/MintCLI/Commands/MintFileCommand.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@

import Foundation
import MintKit
import PathKit
import SwiftCLI

class MintfileCommand: MintCommand {

@Flag("-v", "--verbose", description: "Show verbose output")
var verbose: Bool
private var verbose: Bool

@Flag("-l", "--link", description: "Install the packages of the Mintfile globally")
var link: Bool

@Key("-m", "--mintfile", description: "Custom path to a Mintfile. Defaults to Mintfile")
var mintFile: String?
private var mintFile: String?

override func execute() throws {
try super.execute()
Expand Down
7 changes: 3 additions & 4 deletions Sources/MintCLI/Commands/PackageCommand.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import Foundation
import MintKit
import PathKit
import SwiftCLI

class PackageCommand: MintfileCommand {

@Param var package: String
@Param
private var package: String

@Flag("-s", "--silent", description: "Silences any output from Mint itself")
var silent: Bool
private var silent: Bool

init(mint: Mint, name: String, description: String, parameterDescription: String? = nil) {
var longDescription = """
Expand Down
3 changes: 1 addition & 2 deletions Sources/MintCLI/Commands/RunCommand.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Foundation
import MintKit
import SwiftCLI

class RunCommand: PackageCommand {
final class RunCommand: PackageCommand {

@CollectedParam var arguments: [String]

Expand Down
6 changes: 3 additions & 3 deletions Sources/MintCLI/Commands/UninstallCommand.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation
import MintKit
import SwiftCLI

class UninstallCommand: MintCommand {
final class UninstallCommand: MintCommand {

@Param var package: String
@Param
private var package: String

init(mint: Mint) {
super.init(mint: mint, name: "uninstall", description: "Uninstall a package by name")
Expand Down
6 changes: 3 additions & 3 deletions Sources/MintCLI/Commands/WhichCommand.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation
import MintKit
import SwiftCLI

class WhichCommand: PackageCommand {
final class WhichCommand: PackageCommand {

@Param var executable: String?
@Param
private var executable: String?

init(mint: Mint) {
super.init(mint: mint,
Expand Down
7 changes: 3 additions & 4 deletions Sources/MintCLI/MintCLI.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import Foundation
import MintKit
import PathKit
import Rainbow
import SwiftCLI

public class MintCLI {

public let version = "0.17.5"
private let version = "0.17.5"

let mint: Mint
let cli: CLI
private let mint: Mint
private let cli: CLI

public init() {

Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/Cache.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import PathKit

/// A struct used as a representation of the cache
Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/GitTag.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import Version

func convertTagsToVersionMap(_ tags: [String]) -> [Version: String] {
Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/InputReader.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import SwiftCLI

extension Input {
Expand Down
3 changes: 1 addition & 2 deletions Sources/MintKit/InstallStatus.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import Foundation
import PathKit

struct InstallStatus {

let status: Status
let path: Path
private let path: Path

init(path: Path, mintPackagesPath: Path) throws {
self.path = path
Expand Down
16 changes: 8 additions & 8 deletions Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class Mint {
self.mintFilePath = mintFilePath
}

func output(_ string: String) {
private func output(_ string: String) {
standardOut.print("🌱 \(string)")
}

func errorOutput(_ string: String) {
private func errorOutput(_ string: String) {
standardError.print("🌱 \(string)")
}

Expand All @@ -55,7 +55,7 @@ public class Mint {
var packages: [String: String]
}

func writeMetadata(_ metadata: Metadata) throws {
private func writeMetadata(_ metadata: Metadata) throws {
let data = try JSONEncoder().encode(metadata)
try metadataPath.write(data)
}
Expand All @@ -68,13 +68,13 @@ public class Mint {
return try JSONDecoder().decode(Metadata.self, from: data)
}

func addPackage(git: String, path: Path) throws {
private func addPackage(git: String, path: Path) throws {
var metadata = try readMetadata()
metadata.packages[git] = path.lastComponent
try writeMetadata(metadata)
}

func getGitRepos(name: String) throws -> [String] {
private func getGitRepos(name: String) throws -> [String] {
let metadata = try readMetadata()

let gitRepos = metadata.packages
Expand Down Expand Up @@ -118,7 +118,7 @@ public class Mint {

/// return whether the version was resolved remotely
@discardableResult
func resolvePackage(_ package: PackageReference) throws -> Bool {
private func resolvePackage(_ package: PackageReference) throws -> Bool {

// resolve repo and version from MintFile
if mintFilePath.exists,
Expand Down Expand Up @@ -227,7 +227,7 @@ public class Mint {
return packagePath.executablePath
}

func getPackagePath(for package: PackageReference, with arguments: inout [String], executable: String?) throws -> PackagePath {
private func getPackagePath(for package: PackageReference, with arguments: inout [String], executable: String?) throws -> PackagePath {
var packagePath = PackagePath(path: packagesPath, package: package)

if let executable = executable {
Expand Down Expand Up @@ -455,7 +455,7 @@ public class Mint {
}
}

func linkPackage(_ package: PackageReference, executable: String, overwrite: Bool?) throws {
private func linkPackage(_ package: PackageReference, executable: String, overwrite: Bool?) throws {

let packagePath = PackagePath(path: packagesPath, package: package, executable: executable)
let installPath = linkPath + packagePath.executable!
Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/MintError.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import SwiftCLI

public enum MintError: Error, CustomStringConvertible, Equatable, LocalizedError {
case packageNotFound(String)
Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/Mintfile.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import PathKit

public struct Mintfile {
Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/PackagePath.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import PathKit

/// Contains all the paths for packages
Expand Down
1 change: 0 additions & 1 deletion Sources/MintKit/PackageReference.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import PathKit

public class PackageReference {
public var repo: String
Expand Down
2 changes: 0 additions & 2 deletions Sources/MintKit/StringExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Foundation

public extension String {

var quoted: String {
Expand Down
1 change: 0 additions & 1 deletion Tests/MintTests/Fixtures.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import PathKit

let mintFileFixture = Path(#file) + "../../Fixtures/Mintfile"
Expand Down
1 change: 0 additions & 1 deletion Tests/MintTests/MintfileTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import MintKit
import PathKit
import XCTest

class MintfileTests: XCTestCase {
Expand Down
2 changes: 0 additions & 2 deletions Tests/MintTests/PackageTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
@testable import MintKit
import PathKit
import SwiftCLI
import XCTest

class PackageTests: XCTestCase {
Expand Down
1 change: 0 additions & 1 deletion Tests/MintTests/TestHelpers.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Foundation
import XCTest

func expectError<T>(_ expectedError: T, file: StaticString = #file, line: UInt = #line, closure: () throws -> Void) where T: Error, T: Equatable {
Expand Down