Skip to content

Commit 5dc9498

Browse files
committed
Update mainLet code
1 parent fc3f02d commit 5dc9498

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

Sources/rswift/App.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct GlobalOptions: ParsableArguments {
3434
@Option(help: "Only run specified generators, options: \(generatorsString)", transform: parseGenerators)
3535
var generators: [ResourceType] = []
3636

37+
@Flag(help: "Don't generate main `R` let")
38+
var omitMainLet = false
39+
3740
@Option(name: .customLong("import", withSingleDash: false), help: "Add extra modules as import in the generated file")
3841
var imports: [String] = []
3942

@@ -49,9 +52,6 @@ struct GlobalOptions: ParsableArguments {
4952
@Option(help: "Source of default bundle to use")
5053
var bundleSource: BundleSource = .finder
5154

52-
@Flag(help: "Don't generate main let")
53-
var omitMainLet = false
54-
5555
// MARK: Project specific - Environment variable overrides
5656

5757
@Option(help: "Override environment variable \(EnvironmentKeys.targetName)")

Sources/rswift/RswiftCore.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,30 +298,29 @@ public struct RswiftCore {
298298
.map { "import \($0)" }
299299
.joined(separator: "\n")
300300

301-
let mainLet: String?
302-
switch (bundleSource, omitMainLet) {
303-
case (.module, false):
301+
let mainLet: String
302+
switch bundleSource {
303+
case .module:
304304
mainLet = "\(accessLevel == .publicLevel ? "public " : "")let R = _R(bundle: Bundle.module)"
305-
case (.finder, false):
305+
case .finder:
306306
mainLet = """
307307
private class BundleFinder {}
308308
\(accessLevel == .publicLevel ? "public " : "")let R = _R(bundle: Bundle(for: BundleFinder.self))
309309
"""
310-
default:
311-
mainLet = nil
312310
}
313311

314-
let str = s.prettyPrint()
315-
let body = [imports, mainLet, str].compactMap { $0 }.joined(separator: "\n\n")
316-
let code = """
312+
let body = s.prettyPrint()
313+
314+
let header = """
317315
//
318316
// This is a generated file, do not edit!
319317
// Generated by R.swift, see https://github.com/mac-cain13/R.swift
320318
//
321-
322-
\(body)
323319
"""
324320

321+
let parts = [header, imports, omitMainLet ? nil : mainLet, body].compactMap { $0 }
322+
let code = parts.joined(separator: "\n\n")
323+
325324
try writeIfChanged(contents: code, toURL: outputURL)
326325
}
327326
}

0 commit comments

Comments
 (0)