Skip to content

Commit

Permalink
Update uploadAssets.yml
Browse files Browse the repository at this point in the history
Fix formatting.
  • Loading branch information
LebJe committed Dec 25, 2020
1 parent e7c03e8 commit 791ddd6
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 89 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/uploadAssets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
apt install -yq swiftlang
swift build -c release --enable-test-discovery --static-swift-stdlib -Xswiftc -static-executable
cp .build/release/LFSPointers .
./LFSPointers --generate-completion-script zsh > _LFSPointers
./LFSPointers --generate-completion-script bash > LFSPointers.bash
mkdir LFSPointers-$TAG-linux-arm64
cp .build/release/LFSPointers LFSPointers-$TAG-linux-arm64
tar -czf LFSPointers-${{ github.event.release.tag_name }}-linux-arm64.tar.gz LFSPointers-$TAG-linux-arm64
Expand Down Expand Up @@ -161,6 +163,8 @@ jobs:
run: |
swift build -c release --enable-test-discovery --static-swift-stdlib -Xswiftc -static-executable
cp .build/release/LFSPointers .
./LFSPointers --generate-completion-script zsh > _LFSPointers
./LFSPointers --generate-completion-script bash > LFSPointers.bash
mkdir LFSPointers-$TAG-linux-amd64
cp .build/release/LFSPointers LFSPointers-$TAG-linux-amd64
tar -czf LFSPointers-$TAG-linux-amd64.tar.gz LFSPointers-$TAG-linux-amd64
Expand Down
6 changes: 3 additions & 3 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 100,
"lineLength" : 120,
"maximumBlankLines" : 2,
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : truee,
"AllPublicDeclarationsHaveDocumentation" : true,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : true,
Expand All @@ -30,7 +30,7 @@
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoBlockComments" : true,
"NoBlockComments" : false,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
Expand Down
77 changes: 42 additions & 35 deletions Sources/LFSPointersExecutable/main.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import Foundation
//
// main.swift
//
//
// Created by Jeff Lebrun on 0/00/20.
//

import ArgumentParser
import Rainbow
import Files
import Foundation
import LFSPointersKit
import Rainbow

let jsonStructure = """
[
Expand Down Expand Up @@ -34,16 +41,16 @@ struct LFSPointersCommand: ParsableCommand {
discussion: "JSON STRUCTURE:\n\(jsonStructure)",
version: "3.0.0"
)

@Flag(name: .shortAndLong, help: "Whether to display verbose output.")
var verbose: Bool = false

@Flag(name: .customLong("silent"), help: "Don't print to standard output or standard error.")
var s: Bool = false

@Flag(name: .shortAndLong, help: "Repeat this process in all directories.")
var recursive: Bool = false

@Flag(name: .shortAndLong, help: "Convert all files to pointers (USE WITH CAUTION!).")
var all: Bool = false

Expand All @@ -69,20 +76,20 @@ struct LFSPointersCommand: ParsableCommand {
transform: URL.init(fileURLWithPath:)
)
var backupDirectory: URL? = nil

@Argument(
help: "The directory which contains the files you want to convert to LFS pointers.",
completion: .directory,
transform: URL.init(fileURLWithPath:)
)
var directory: URL

@Argument(
help: "A list of paths to files, relative to the current directory, that represent files to be converted. You can use your shell's regular expression support to pass in a list of files.",
completion: .file()
)
var files: [String] = []

mutating func validate() throws {
// Verify the directory actually exists.
guard FileManager().fileExists(atPath: directory.path) else {
Expand All @@ -97,22 +104,22 @@ struct LFSPointersCommand: ParsableCommand {
}
}
}

func run() throws {
var silent = false

if s {
silent = true
}

if json {
silent = true
}

if !color {
Rainbow.enabled = false
}

let printClosure: (URL, Status) -> Void = { url, status in
switch status {
case let .appending(pointer):
Expand All @@ -122,17 +129,17 @@ struct LFSPointersCommand: ParsableCommand {
} else if !silent {
print("Appending pointer to file \"\(file.name)\"...")
}

case let .error(error):
let file = try! File(path: url.path)

if self.verbose && !silent {
if self.color {
fputs("Could not convert \"\(file.name)\" to a pointer.\n Git LFS error: \(error)\n".red, stderr)
} else {
fputs("Could not convert \"\(file.name)\" to a pointer.\n Git LFS error: \(error)\n", stderr)
}

} else if !silent {
if self.color {
fputs("Could not convert \"\(file.name)\" to a pointer.".red, stderr)
Expand All @@ -141,22 +148,22 @@ struct LFSPointersCommand: ParsableCommand {
}
}
break

case .generating:
let file = try! File(path: url.path)

if !silent && self.verbose {
print("Converting \"\(file.name)\" to pointer...\n")
} else if !silent {
print("Converting \"\(file.name)\" to pointer...\n")
}
case let .regexDoesntMatch(regex):
let file = try! File(path: url.path)

if !silent && self.verbose {
print("File name \"\(file.name)\" does not match regular expression \"\(regex.pattern)\", continuing...")
}

case let .writing(pointer):
let file = try! File(path: url.path)
if self.verbose && !silent {
Expand All @@ -166,7 +173,7 @@ struct LFSPointersCommand: ParsableCommand {
}
}
}

do {

if all {
Expand All @@ -180,13 +187,13 @@ struct LFSPointersCommand: ParsableCommand {
Foundation.exit(0)
}
}

if let bd = backupDirectory {
do {
if !silent {
print("Copying files to backup directory...")
}

// Copy the specified directory into the backup directory.
try Folder(path: directory.path).copy(to: Folder(path: bd.path))
} catch {
Expand All @@ -204,22 +211,22 @@ struct LFSPointersCommand: ParsableCommand {
)
}
}

Foundation.exit(4)
}
}

if all {
let pointers = try LFSPointer.pointers(
forDirectory: directory,
searchType: .all,
recursive: recursive,
statusClosure: printClosure
)

if !json {
pointers.forEach({ p in

do {
try p.write(
toFile: URL(fileURLWithPath: p.filePath),
Expand All @@ -240,7 +247,7 @@ struct LFSPointersCommand: ParsableCommand {
fputs("Unable to overwrite file \"\(p.filename)\". Error: \(error)", stderr)
}
}

})
} else {
do {
Expand All @@ -261,10 +268,10 @@ struct LFSPointersCommand: ParsableCommand {
recursive: recursive,
statusClosure: printClosure
)

if !json {
pointers.forEach({ p in

do {
try p.write(
toFile: URL(fileURLWithPath: p.filePath),
Expand All @@ -286,7 +293,7 @@ struct LFSPointersCommand: ParsableCommand {
fputs("Unable to overwrite file \"\(p.filename)\". Error: \(error)", stderr)
}
}

})
} else {
do {
Expand All @@ -299,7 +306,7 @@ struct LFSPointersCommand: ParsableCommand {
}

}

} catch let error {
if !silent {

Expand All @@ -310,10 +317,10 @@ struct LFSPointersCommand: ParsableCommand {
}

}

Foundation.exit(2)
}

if !silent {

if self.color {
Expand Down
9 changes: 4 additions & 5 deletions Sources/LFSPointersKit/Enums.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Enums.swift
//
//
//
// Created by Jeff Lebrun on 4/16/20.
//
Expand All @@ -9,18 +9,17 @@ import Foundation

/// The search types to use when filtering files.
public enum SearchTypes {

/// Searches for all files that match any of the filenames in the array.
case fileNames([URL])

/// Searches for all files whose name matches the regular expression.
case regex(NSRegularExpression)

/// Searches for all files.
case all
}


public enum Status {
case writing(LFSPointer),
appending(LFSPointer),
Expand Down
3 changes: 2 additions & 1 deletion Sources/LFSPointersKit/Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Extensions.swift
//
//
//
// Created by Jeff Lebrun on 4/14/20.
//
Expand All @@ -9,6 +9,7 @@ import Foundation

public extension NSRegularExpression {
/// Checks if this regular expression matches the supplied `String`.
///
/// - Returns: `true` if the `String` matches, otherwise, `false`.
func matches(_ string: String) -> Bool {
firstMatch(in: string, options: [], range: NSRange(location: 0, length: string.utf16.count)) != nil
Expand Down
Loading

0 comments on commit 791ddd6

Please sign in to comment.