This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
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
9 changed files
with
411 additions
and
140 deletions.
There are no files selected for viewing
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
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,119 @@ | ||
!default.mode1v3 | ||
!default.mode2v3 | ||
!default.pbxuser | ||
!default.perspectivev3 | ||
!default.xcworkspace | ||
*.dSYM | ||
*.dSYM.zip | ||
*.hmap | ||
*.ipa | ||
*.lcov | ||
*.lock | ||
*.log | ||
*.mode1v3 | ||
*.mode2v3 | ||
*.moved-aside | ||
*.pbxuser | ||
*.perspectivev3 | ||
*.pid | ||
*.pid.lock | ||
*.seed | ||
*.swp | ||
*.tgz | ||
*.tsbuildinfo | ||
*.xccheckout | ||
*.xcscmblueprint | ||
*.xcuserstate | ||
*~.nib | ||
.AppleDB | ||
.AppleDesktop | ||
.AppleDouble | ||
.DS_Store | ||
.DocumentRevisions-V100 | ||
.LSOverride | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
._* | ||
.apdisk | ||
.build | ||
.bundle | ||
.cache | ||
.cache/ | ||
.com.apple.timemachine.donotpresent | ||
.dynamodb/ | ||
.env | ||
.env.test | ||
.eslintcache | ||
.fseventsd | ||
.fusebox/ | ||
.grunt | ||
.idea | ||
.lock-wscript | ||
.next | ||
.node_repl_history | ||
.npm | ||
.nuxt | ||
.nyc_output | ||
.parcel-cache | ||
.pnp.* | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
.serverless/ | ||
.swiftpm | ||
.tern-port | ||
.vscode-test | ||
.vuepress/dist | ||
.yarn-integrity | ||
.yarn/build-state.yml | ||
.yarn/cache | ||
.yarn/unplugged | ||
/*.gcno | ||
Artifacts/ | ||
CI | ||
CI-Pods.tar | ||
Carthage/Build | ||
Carthage/Build/ | ||
DerivedData | ||
DerivedData/ | ||
Icon | ||
Network Trash Folder | ||
Pipeline/Dockers/Buildtime/ | ||
Podfile.lock | ||
Pods/ | ||
Temporary Items | ||
artifacts/ | ||
bower_components | ||
build/ | ||
build/Release | ||
coverage | ||
default.profraw | ||
dist | ||
dockerbuild | ||
dockermnt | ||
fastlane/Preview.html | ||
fastlane/report.xml | ||
fastlane/screenshots/**/*.png | ||
fastlane/test_output | ||
iOSInjectionProject/ | ||
jspm_packages/ | ||
lerna-debug.log* | ||
lib-cov | ||
logs | ||
node_modules/ | ||
npm-debug.log* | ||
pids | ||
profile | ||
project.xcworkspace | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
temp/ | ||
temps/ | ||
web_modules/ | ||
xcuserdata | ||
xcuserdata/ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
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,52 @@ | ||
# AuxiliaryExecute | ||
|
||
A Swift wrapper for system shell over posix_spawn with search path and env support. | ||
|
||
## Usage | ||
|
||
``` | ||
import AuxiliaryExecute | ||
AuxiliaryExecute.local.bash(command: "echo nya") | ||
``` | ||
|
||
## Customization & Defaults | ||
|
||
The source for this package is well explained in details along with comments. Feel free looking for them. | ||
|
||
``` | ||
// automatically search for binary within env PATH | ||
let result = AuxiliaryExecute.local.shell( | ||
command: "bash", | ||
args: ["-c", "echo $mua"], | ||
environment: ["mua": "nya"], | ||
timeout: 0 | ||
) { stdout in | ||
print(stdout) | ||
} stderrBlock: { stderr in | ||
print(stderr) | ||
} | ||
// or call with binary's full path | ||
func spawn( | ||
command: String, | ||
args: [String] = [], | ||
environment: [String: String] = [:], | ||
timeout: Double = 0, | ||
stdoutBlock: ((String) -> Void)? = nil, | ||
stderrBlock: ((String) -> Void)? = nil | ||
) | ||
// for customize option for shell | ||
func appendSearchPath(with value: String) | ||
func updateExtraSearchPath(with block: (inout [String]) -> Void) | ||
func updateOverwriteTable(with block: (inout [String: String?]) -> Void) | ||
``` | ||
|
||
## License | ||
|
||
AuxiliaryExecute is licensed under [MIT](./LICENSE). | ||
|
||
--- | ||
|
||
Copyright © 2021 Lakr Aream. All Rights Reserved. |
76 changes: 76 additions & 0 deletions
76
Foundation/AuxiliaryExecute/Sources/AuxiliaryExecute/AuxiliaryExecute+Async.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,76 @@ | ||
// | ||
// AuxiliaryExecute+Spawn.swift | ||
// AuxiliaryExecute | ||
// | ||
// Created by Cyandev on 2022/1/10. | ||
// | ||
|
||
#if swift(>=5.5) | ||
|
||
import Foundation | ||
|
||
@available(iOS 15.0, macOS 12.0.0, *) | ||
public extension AuxiliaryExecute { | ||
/// async/await function for spawn using withCheckedContinuation | ||
/// - Parameters: | ||
/// - command: full path of the binary file. eg: "/bin/cat" | ||
/// - args: arg to pass to the binary, exclude argv[0] which is the path itself. eg: ["nya"] | ||
/// - environment: any environment to be appended/overwrite when calling posix spawn. eg: ["mua" : "nya"] | ||
/// - timeout: any wall timeout if lager than 0, in seconds. eg: 6 | ||
/// - stdout: a block call from pipeControlQueue in background when buffer from stdout available for read | ||
/// - stderr: a block call from pipeControlQueue in background when buffer from stderr available for read | ||
/// - Returns: execution recipe, see it's definition for details | ||
@discardableResult | ||
static func spawnAsync( | ||
command: String, | ||
args: [String] = [], | ||
environment: [String: String] = [:], | ||
timeout: Double = 0, | ||
stdoutBlock: ((String) -> Void)? = nil, | ||
stderrBlock: ((String) -> Void)? = nil | ||
) async -> ExecuteRecipe { | ||
await withCheckedContinuation { cont in | ||
self.spawn( | ||
command: command, | ||
args: args, | ||
environment: environment, | ||
timeout: timeout, | ||
stdoutBlock: stdoutBlock, | ||
stderrBlock: stderrBlock | ||
) { recipe in | ||
cont.resume(returning: recipe) | ||
} | ||
} | ||
} | ||
|
||
/// async/await function for spawn using withCheckedContinuation | ||
/// - Parameters: | ||
/// - command: full path of the binary file. eg: "/bin/cat" | ||
/// - args: arg to pass to the binary, exclude argv[0] which is the path itself. eg: ["nya"] | ||
/// - environment: any environment to be appended/overwrite when calling posix spawn. eg: ["mua" : "nya"] | ||
/// - timeout: any wall timeout if lager than 0, in seconds. eg: 6 | ||
/// - output: a block call from pipeControlQueue in background when buffer from stdout or stderr available for read | ||
/// - Returns: execution recipe, see it's definition for details | ||
@discardableResult | ||
static func spawnAsync( | ||
command: String, | ||
args: [String] = [], | ||
environment: [String: String] = [:], | ||
timeout: Double = 0, | ||
output: ((String) -> Void)? = nil | ||
) async -> ExecuteRecipe { | ||
await spawnAsync( | ||
command: command, | ||
args: args, | ||
environment: environment, | ||
timeout: timeout, | ||
stdoutBlock: { str in | ||
output?(str) | ||
}, stderrBlock: { str in | ||
output?(str) | ||
} | ||
) | ||
} | ||
} | ||
|
||
#endif |
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
Oops, something went wrong.