Skip to content

Commit 0fac0a7

Browse files
committed
[feat]: timer & folderSequence
1 parent 56beb84 commit 0fac0a7

29 files changed

+175
-522
lines changed

folderSequence/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/

folderSequence/Bin/folderSequence

1.42 MB
Binary file not shown.

timer/Package.resolved renamed to folderSequence/Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

folderSequence/Package.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "folderSequence",
8+
dependencies: [
9+
// Dependencies declare other packages that this package depends on.
10+
.package(url: "https://github.com/JohnSundell/Files.git", from: "4.1.1"),
11+
.package(url: "https://github.com/kareman/Moderator.git", from: "0.5.1"),
12+
.package(url: "https://github.com/DanielCech/ScriptToolkit.git", .branch("master")),
13+
.package(url: "https://github.com/kareman/SwiftShell.git", from: "5.0.1"),
14+
.package(url: "https://github.com/kareman/FileSmith.git", from: "0.3.0")
15+
],
16+
targets: [
17+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
18+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
19+
.target(
20+
name: "folderSequence",
21+
dependencies: ["Files", "FileSmith", "SwiftShell", "ScriptToolkit", "Moderator"]),
22+
.testTarget(
23+
name: "folderSequenceTests",
24+
dependencies: ["folderSequence"]),
25+
]
26+
)

folderSequence/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# folderSequence
2+
3+
A description of this package.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Foundation
2+
3+
import Files
4+
import Foundation
5+
import Moderator
6+
import ScriptToolkit
7+
import SwiftShell
8+
9+
let moderator = Moderator(description: "Creates a sequence of folders")
10+
moderator.usageFormText = "foldersequence <params>"
11+
12+
let fromArgument = moderator.add(Argument<String?>
13+
.optionWithValue("from", name: "Initial number", description: ""))
14+
15+
let toArgument = moderator.add(Argument<String?>
16+
.optionWithValue("to", name: "Final number", description: ""))
17+
18+
do {
19+
try moderator.parse()
20+
21+
guard
22+
let fromString = fromArgument.value,
23+
let from = Int(fromString),
24+
let toString = toArgument.value,
25+
let to = Int(toString)
26+
else {
27+
print(moderator.usagetext)
28+
exit(0)
29+
}
30+
31+
print("⌚️ Processing")
32+
33+
34+
35+
for index in from ... to {
36+
let dirName = String(format: "%03d", index)
37+
try Folder.current.createSubfolder(named: dirName)
38+
}
39+
40+
41+
print("✅ Done")
42+
}
43+
catch {
44+
if let printableError = error as? PrintableError { print(printableError.errorDescription) }
45+
else {
46+
print(error.localizedDescription)
47+
}
48+
49+
exit(Int32(error._code))
50+
}

folderSequence/Tests/LinuxMain.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import XCTest
2+
3+
import folderSequenceTests
4+
5+
var tests = [XCTestCaseEntry]()
6+
tests += folderSequenceTests.allTests()
7+
XCTMain(tests)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import XCTest
2+
3+
#if !canImport(ObjectiveC)
4+
public func allTests() -> [XCTestCaseEntry] {
5+
return [
6+
testCase(folderSequenceTests.allTests),
7+
]
8+
}
9+
#endif
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import XCTest
2+
import class Foundation.Bundle
3+
4+
final class folderSequenceTests: XCTestCase {
5+
func testExample() throws {
6+
// This is an example of a functional test case.
7+
// Use XCTAssert and related functions to verify your tests produce the correct
8+
// results.
9+
10+
// Some of the APIs that we use below are available in macOS 10.13 and above.
11+
guard #available(macOS 10.13, *) else {
12+
return
13+
}
14+
15+
let fooBinary = productsDirectory.appendingPathComponent("folderSequence")
16+
17+
let process = Process()
18+
process.executableURL = fooBinary
19+
20+
let pipe = Pipe()
21+
process.standardOutput = pipe
22+
23+
try process.run()
24+
process.waitUntilExit()
25+
26+
let data = pipe.fileHandleForReading.readDataToEndOfFile()
27+
let output = String(data: data, encoding: .utf8)
28+
29+
XCTAssertEqual(output, "Hello, world!\n")
30+
}
31+
32+
/// Returns path to the built products directory.
33+
var productsDirectory: URL {
34+
#if os(macOS)
35+
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
36+
return bundle.bundleURL.deletingLastPathComponent()
37+
}
38+
fatalError("couldn't find the products directory")
39+
#else
40+
return Bundle.main.bundleURL
41+
#endif
42+
}
43+
44+
static var allTests = [
45+
("testExample", testExample),
46+
]
47+
}

folderSequence/install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /bin/bash
2+
swift build
3+
cp -rf .build/x86_64-apple-macosx/debug/folderSequence Bin
4+
cp -rf .build/x86_64-apple-macosx/debug/folderSequence /usr/local/bin

0 commit comments

Comments
 (0)