From 64db75fb44ab671fbdd52c876c9b7d4c8cc43c6a Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Fri, 9 Sep 2022 11:00:12 +0200 Subject: [PATCH] Read config path from command line --- .../xcshareddata/xcschemes/WebsiteGenerator.xcscheme | 6 ++++++ WebsiteGenerator/Generators/PageGenerator.swift | 3 ++- WebsiteGenerator/main.swift | 9 ++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/WebsiteGenerator.xcodeproj/xcshareddata/xcschemes/WebsiteGenerator.xcscheme b/WebsiteGenerator.xcodeproj/xcshareddata/xcschemes/WebsiteGenerator.xcscheme index dbac244..e9417bd 100644 --- a/WebsiteGenerator.xcodeproj/xcshareddata/xcschemes/WebsiteGenerator.xcscheme +++ b/WebsiteGenerator.xcodeproj/xcshareddata/xcschemes/WebsiteGenerator.xcscheme @@ -50,6 +50,12 @@ ReferencedContainer = "container:WebsiteGenerator.xcodeproj"> + + + + (content: String, includesCode: Bool, isEmpty: Bool) { - if let raw = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: true)? + let create = configuration.createMdFilesIfMissing + if let raw = files.contentOfOptionalFile(atPath: path, source: page.path, createEmptyFileIfMissing: create)? .trimmed.nonEmpty { let (content, includesCode) = PageContentGenerator(factory: factory.factory) .generate(page: page, language: language, content: raw) diff --git a/WebsiteGenerator/main.swift b/WebsiteGenerator/main.swift index 5b76433..4415cfd 100644 --- a/WebsiteGenerator/main.swift +++ b/WebsiteGenerator/main.swift @@ -1,10 +1,17 @@ import Foundation -let configUrl = URL(fileURLWithPath: "/Users/ch/Projects/MakerSpace/CHGenerator/config.json") +let args = CommandLine.arguments + +guard args.count == 2 else { + print("Invalid argument list") + print("Usage: generator config-path") + exit(1) +} let configuration: Configuration do { + let configUrl = URL(fileURLWithPath: args[1]) let data = try Data(contentsOf: configUrl) configuration = try JSONDecoder().decode(from: data) } catch {