Initial commit
This commit is contained in:
commit
a568b40ddc
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
||||||
|
xcuserdata/
|
||||||
|
DerivedData/
|
||||||
|
.swiftpm/config/registries.json
|
||||||
|
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||||
|
.netrc
|
22
Package.swift
Normal file
22
Package.swift
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// swift-tools-version: 5.6
|
||||||
|
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||||
|
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "fancyclip",
|
||||||
|
dependencies: [
|
||||||
|
// Dependencies declare other packages that this package depends on.
|
||||||
|
// .package(url: /* package url */, from: "1.0.0"),
|
||||||
|
],
|
||||||
|
targets: [
|
||||||
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
|
// Targets can depend on other targets in this package, and on products in packages this package depends on.
|
||||||
|
.executableTarget(
|
||||||
|
name: "fancyclip",
|
||||||
|
dependencies: []),
|
||||||
|
.testTarget(
|
||||||
|
name: "fancyclipTests",
|
||||||
|
dependencies: ["fancyclip"]),
|
||||||
|
]
|
||||||
|
)
|
BIN
Sources/fancyclip/.main.swift.swp
Normal file
BIN
Sources/fancyclip/.main.swift.swp
Normal file
Binary file not shown.
17
Sources/fancyclip/main.swift
Executable file
17
Sources/fancyclip/main.swift
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
import Foundation
|
||||||
|
import Cocoa
|
||||||
|
|
||||||
|
let cmd = (CommandLine.arguments[0] as NSString).lastPathComponent
|
||||||
|
|
||||||
|
if CommandLine.arguments.count < 3 {
|
||||||
|
fputs("usage: \(cmd) LABEL URL\n", stderr)
|
||||||
|
exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let label = CommandLine.arguments[1]
|
||||||
|
let url = CommandLine.arguments[2]
|
||||||
|
|
||||||
|
let pasteBoard = NSPasteboard.general
|
||||||
|
pasteBoard.clearContents()
|
||||||
|
pasteBoard.setString("[\(label)](\(url))", forType: .string)
|
||||||
|
pasteBoard.setString("<a href=\"\(url)\">\(label)</a>", forType: .html)
|
47
Tests/fancyclipTests/fancyclipTests.swift
Normal file
47
Tests/fancyclipTests/fancyclipTests.swift
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import XCTest
|
||||||
|
import class Foundation.Bundle
|
||||||
|
|
||||||
|
final class fancyclipTests: XCTestCase {
|
||||||
|
func testExample() throws {
|
||||||
|
// This is an example of a functional test case.
|
||||||
|
// Use XCTAssert and related functions to verify your tests produce the correct
|
||||||
|
// results.
|
||||||
|
|
||||||
|
// Some of the APIs that we use below are available in macOS 10.13 and above.
|
||||||
|
guard #available(macOS 10.13, *) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mac Catalyst won't have `Process`, but it is supported for executables.
|
||||||
|
#if !targetEnvironment(macCatalyst)
|
||||||
|
|
||||||
|
let fooBinary = productsDirectory.appendingPathComponent("fancyclip")
|
||||||
|
|
||||||
|
let process = Process()
|
||||||
|
process.executableURL = fooBinary
|
||||||
|
|
||||||
|
let pipe = Pipe()
|
||||||
|
process.standardOutput = pipe
|
||||||
|
|
||||||
|
try process.run()
|
||||||
|
process.waitUntilExit()
|
||||||
|
|
||||||
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
let output = String(data: data, encoding: .utf8)
|
||||||
|
|
||||||
|
XCTAssertEqual(output, "Hello, world!\n")
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns path to the built products directory.
|
||||||
|
var productsDirectory: URL {
|
||||||
|
#if os(macOS)
|
||||||
|
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
|
||||||
|
return bundle.bundleURL.deletingLastPathComponent()
|
||||||
|
}
|
||||||
|
fatalError("couldn't find the products directory")
|
||||||
|
#else
|
||||||
|
return Bundle.main.bundleURL
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user