Skip to content

Commit fee0fe0

Browse files
Merge pull request #2 from subdiox/main
Add support for current AtCoder
2 parents ddbda6a + bf58bf0 commit fee0fe0

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

Sources/AtCoderLibrary/API/OjApiCommand.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,10 @@ enum OjApiCommand {
55
static func getAllTasks(url: String, ojApiPath: String) throws -> (contest: Contest, problems: [Problem]) {
66
let contest = try OjApiCommand.getContest(url: url, ojApiPath: ojApiPath)
77
var problems = [Problem]()
8-
let operation = BlockOperation()
9-
var error: Error?
10-
contest.problems.forEach { problem in
11-
operation.addExecutionBlock {
12-
do {
13-
let problem = try OjApiCommand.getProblem(url: problem.url, ojApiPath: ojApiPath)
14-
.apply(context: problem.context)
15-
problems.append(problem)
16-
} catch(let e) {
17-
error = e
18-
operation.cancel()
19-
}
20-
}
21-
}
22-
operation.start()
23-
24-
if operation.isCancelled, let error = error {
25-
throw error
8+
for problem in contest.problems {
9+
let problem = try OjApiCommand.getProblem(url: problem.url, ojApiPath: ojApiPath)
10+
.apply(context: problem.context)
11+
problems.append(problem)
2612
}
2713
return (contest, problems)
2814
}

Sources/AtCoderLibrary/Command/New.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct New: ParsableCommand {
2626
try FileManager.default.createDirectory(atPath: contestName, withIntermediateDirectories: true)
2727
FileManager.default.changeCurrentDirectoryPath(contestName)
2828

29-
let alphabets = problems.map(\.context.alphabet).map(Character.init)
29+
let alphabets = problems.map(\.context.alphabet)
3030
try PackageSwift(contestName: contestName, alphabets: alphabets).codeGenerate()
3131
try Readme(contest: contest, problems: problems).codeGenerate()
3232
try problems.forEach {

Sources/AtCoderLibrary/Command/New/Templates/PackageSwift.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct PackageSwift: CodeTemplate {
22
let contestName: String
3-
let alphabets: [Character]
3+
let alphabets: [String]
44
let fileName = "Package.swift"
55
let directory: String? = nil
66
var source: String {
@@ -12,8 +12,7 @@ struct PackageSwift: CodeTemplate {
1212
name: "\(contestName.uppercased())",
1313
dependencies: [],
1414
targets: [
15-
\(alphabets.sorted()
16-
.map {
15+
\(alphabets.map {
1716
"""
1817
.target(name: "\($0)"),
1918
.testTarget(name: "\($0)Tests", dependencies: ["\($0)", "TestLibrary"]),

Tests/AtCoderLibraryTests/Command/New/Generator/PackageTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Foundation
55
final class PackageTests: XCTestCase {
66
func test() throws {
77
let contestName = "abc001"
8-
let alphabets: [Character] = ["A", "B", "C"]
8+
let alphabets = ["A", "B", "C"]
99
let package = PackageSwift(contestName: contestName, alphabets: alphabets)
1010
let expected = """
1111
// swift-tools-version:5.3

0 commit comments

Comments
 (0)