Initial commit

This commit is contained in:
Annika Backstrom 2022-06-08 22:50:04 +01:00
commit a568b40ddc
6 changed files with 98 additions and 0 deletions

9
.gitignore vendored Normal file
View 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
View 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"]),
]
)

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# fancyclip
A description of this package.

Binary file not shown.

17
Sources/fancyclip/main.swift Executable file
View 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)

View 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
}
}