Skip to content

Commit

Permalink
Throw an error if can't parse default-config
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Oct 7, 2023
1 parent 280bb74 commit 3fc9ec6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
4 changes: 4 additions & 0 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
93D44EA41776738B4758C28D /* util.swift in Sources */ = {isa = PBXBuildFile; fileRef = 976540EBEACF846D598CD6E1 /* util.swift */; };
9A138A729245BD2723148583 /* focused.swift in Sources */ = {isa = PBXBuildFile; fileRef = D61FE8B343B068F0FFFC2373 /* focused.swift */; };
9D34BD7DE311254BF52F5EA2 /* testUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77C03164B8BFD1E59779C6E /* testUtil.swift */; };
9FF829BA48F9AE6E46D8467C /* ScopeFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D113ECDD9173131C0C89630 /* ScopeFunctions.swift */; };
A0765C31043BCFB0420BF1C9 /* parseConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67DBAF4ECF8A0B931FC34EAD /* parseConfig.swift */; };
A2CBF9674964F9083BB198D2 /* ArrayEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 883D7F7F87FBE7D0BDE4E87F /* ArrayEx.swift */; };
A55F31B0CC357B37108B8F54 /* MoveContainerToWorkspaceCommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DBD002C4A68AED07BB63EFA /* MoveContainerToWorkspaceCommandTest.swift */; };
Expand Down Expand Up @@ -96,6 +97,7 @@
3C2E5977331398421A4FC168 /* GlobalObserver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlobalObserver.swift; sourceTree = "<group>"; };
43DD32B1711B8EFCC834B68E /* WorkspaceCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceCommand.swift; sourceTree = "<group>"; };
4B0CD3C2A0E86CDB9DF312AB /* ModeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModeCommand.swift; sourceTree = "<group>"; };
4D113ECDD9173131C0C89630 /* ScopeFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScopeFunctions.swift; sourceTree = "<group>"; };
51CE37C1B8D858C81A396F40 /* CollectionEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionEx.swift; sourceTree = "<group>"; };
526B113159987FA43EA41120 /* refresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = refresh.swift; sourceTree = "<group>"; };
5274C575044C2A7123C57584 /* AeroSpace-Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "AeroSpace-Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -315,6 +317,7 @@
AF3BB3DD434C75536217CB88 /* NSScreenEx.swift */,
A9EDFD4A9F45182CA6E0BD7B /* OptionalEx.swift */,
28B788A95DD3C267878E05B5 /* Rect.swift */,
4D113ECDD9173131C0C89630 /* ScopeFunctions.swift */,
AAE5DCAEC5EE619CE33859E7 /* SequenceEx.swift */,
976540EBEACF846D598CD6E1 /* util.swift */,
381743262EB4D8AB365235C8 /* Writer.swift */,
Expand Down Expand Up @@ -462,6 +465,7 @@
78EE0CEF814ABDBA67941B84 /* Rect.swift in Sources */,
FC35D6D0A678CC802972C6FE /* ReloadConfigCommand.swift in Sources */,
D24D02B1FD87424B908986AF /* ResizeCommand.swift in Sources */,
9FF829BA48F9AE6E46D8467C /* ScopeFunctions.swift in Sources */,
AE76A183D0454E4C8ADCE380 /* SequenceEx.swift in Sources */,
E5682579AEC6B84CF6FCE90D /* TilingContainer.swift in Sources */,
56E72B24303F5F337B31B776 /* TrayMenuModel.swift in Sources */,
Expand Down
10 changes: 8 additions & 2 deletions src/config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import HotKey

let mainModeId = "main" // todo rename to "default"
let defaultConfig =
parseConfig(try! String(contentsOf: Bundle.main.url(forResource: "default-config", withExtension: "toml")!)).value
parseConfig(try! String(contentsOf: Bundle.main.url(forResource: "default-config", withExtension: "toml")!))
.also {
if !$0.log.isEmpty {
error("Can't parse default config: \($0)")
}
}
.value
var config: Config = defaultConfig

struct Config {
struct Config: ScopeFunctions {
var afterStartupCommand: Command
var afterLoginCommand: Command
var usePaddingForNestedContainersWithTheSameOrientation: Bool // todo
Expand Down
18 changes: 18 additions & 0 deletions src/util/ScopeFunctions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
protocol ScopeFunctions {}

extension ScopeFunctions {
@discardableResult
func apply(_ block: (Self) -> Void) -> Self {
block(self)
return self
}

@discardableResult
func also(_ block: (Self) -> Void) -> Self {
block(self)
return self
}
}

extension TreeNode: ScopeFunctions {}
extension Writer: ScopeFunctions {}
2 changes: 1 addition & 1 deletion test/command/FlattenWorkspaceTreeCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class FlattenWorkspaceTreeCommandTest: XCTestCase {

func testSimple() async {
let workspace = Workspace.get(byName: name).apply {
($0 as! Workspace).rootTilingContainer.apply {
$0.rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).focus()
TilingContainer.newHList(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0)
Expand Down
2 changes: 1 addition & 1 deletion test/command/MoveThroughCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ final class MoveThroughCommandTest: XCTestCase {

func testCreateImplicitContainer() async {
let workspace = Workspace.get(byName: name).apply { // Don't cache root
($0 as! Workspace).rootTilingContainer.apply {
$0.rootTilingContainer.apply {
TestWindow(id: 1, parent: $0)
TestWindow(id: 2, parent: $0).focus()
TestWindow(id: 3, parent: $0)
Expand Down
8 changes: 0 additions & 8 deletions test/testUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,3 @@ func tearDownWorkspacesForTests() {
}
}
}

extension TreeNode {
@discardableResult
func apply(_ block: (Self) -> Void) -> Self {
block(self)
return self
}
}

0 comments on commit 3fc9ec6

Please sign in to comment.