forked from 100mango/zen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
774 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
122 changes: 122 additions & 0 deletions
122
基于 Swift 编写严肃脚本工具/script/.swiftpm/xcode/xcshareddata/xcschemes/script.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1250" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "script" | ||
BuildableName = "script" | ||
BlueprintName = "script" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "scriptTests" | ||
BuildableName = "scriptTests" | ||
BlueprintName = "scriptTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "core" | ||
BuildableName = "core" | ||
BlueprintName = "core" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "scriptTests" | ||
BuildableName = "scriptTests" | ||
BlueprintName = "scriptTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "script" | ||
BuildableName = "script" | ||
BlueprintName = "script" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
<CommandLineArguments> | ||
<CommandLineArgument | ||
argument = "--help" | ||
isEnabled = "YES"> | ||
</CommandLineArgument> | ||
</CommandLineArguments> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "script" | ||
BuildableName = "script" | ||
BlueprintName = "script" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "swift-argument-parser", | ||
"repositoryURL": "https://github.com/apple/swift-argument-parser", | ||
"state": { | ||
"branch": null, | ||
"revision": "986d191f94cec88f6350056da59c2e59e83d1229", | ||
"version": "0.4.3" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// swift-tools-version:5.4 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "script", | ||
platforms: [ | ||
.macOS(.v11) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.4.0") | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "script", | ||
dependencies: [ | ||
.product(name: "ArgumentParser", package: "swift-argument-parser")]), | ||
.target( | ||
name: "core", | ||
dependencies: []), | ||
.testTarget( | ||
name: "scriptTests", | ||
dependencies: ["script"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# script | ||
|
||
A description of this package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by 100mango on 2021/6/26. | ||
// | ||
|
||
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
|
||
// | ||
//import Darwin | ||
// | ||
////let arguments: [String] = Array(CommandLine.arguments.dropFirst()) | ||
//// | ||
////guard let numberString = arguments.first else { | ||
//// print("no argument") | ||
//// exit(1) | ||
////} | ||
//// | ||
////guard let number = UInt(numberString) else { | ||
//// print("no unsigned number") | ||
//// exit(1) | ||
////} | ||
//// | ||
////print(UInt.random(in: 0...number)) | ||
////exit(0) | ||
// | ||
//import ArgumentParser | ||
// | ||
//struct Random: ParsableCommand { | ||
// @Argument(help: "unsigned number") | ||
// var highValue: UInt | ||
// | ||
// func run() { | ||
// print(UInt.random(in: 0...highValue)) | ||
// } | ||
//} | ||
// | ||
//Random.main() | ||
|
||
//import AppKit | ||
// | ||
//NSApplication.shared.setActivationPolicy(.accessory) | ||
// | ||
//func selectFile() -> URL? { | ||
// let dialog = NSOpenPanel() | ||
// dialog.allowedFileTypes = ["jpg", "png"] | ||
// guard dialog.runModal() == .OK else { return nil } | ||
// return dialog.url | ||
//} | ||
// | ||
//print (selectFile()?.absoluteString ?? "") | ||
|
||
import SwiftUI | ||
|
||
struct App: SwiftUI.App { | ||
@State var filename = "Filename" | ||
@State var showFileChooser = false | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
HStack { | ||
Text(filename) | ||
Button ("select File") | ||
{ | ||
let panel = NSOpenPanel() | ||
panel.allowsMultipleSelection = false | ||
panel.canChooseDirectories = false | ||
if panel.runModal() == .OK { | ||
self.filename = panel.url?.lastPathComponent ?? "<none>" | ||
} | ||
} | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
.windowStyle(HiddenTitleBarWindowStyle()) | ||
} | ||
} | ||
App.main() |
47 changes: 47 additions & 0 deletions
47
基于 Swift 编写严肃脚本工具/script/Tests/scriptTests/scriptTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import XCTest | ||
import class Foundation.Bundle | ||
|
||
final class scriptTests: 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("script") | ||
|
||
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.