Skip to content

Commit

Permalink
Fixed empty finalAction array issue
Browse files Browse the repository at this point in the history
* Updated Surfile content for supporting FinalAction.
* Updated surmagic binary
  • Loading branch information
gurhub committed Feb 6, 2022
1 parent a84ed75 commit 48f78d4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 55 deletions.
54 changes: 29 additions & 25 deletions Demo/SM/Surfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>output_path</key>
<string>build</string>
<key>framework</key>
<string>xcf</string>
<key>targets</key>
<array>
<dict>
<key>sdk</key>
<string>iOS</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
<dict>
<key>sdk</key>
<string>iOSSimulator</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
</array>
</dict>
<dict>
<key>output_path</key>
<string>build</string>
<key>framework</key>
<string>xcf</string>
<key>targets</key>
<array>
<dict>
<key>sdk</key>
<string>iOS</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
<dict>
<key>sdk</key>
<string>iOSSimulator</string>
<key>workspace</key>
<string>surmagic-demo.xcworkspace</string>
<key>scheme</key>
<string>xcf</string>
</dict>
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>
</plist>
Binary file modified bin/surmagic
Binary file not shown.
19 changes: 19 additions & 0 deletions surmagic/Sources/surmagic/FinalAction.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// FinalAction.swift
// Surmagic
//
// Created by Muhammed Gurhan Yerlikaya on 6.02.2022.
// Copyright © 2022 https://github.com/gurhub/surmagic.
//

import Foundation

public enum FinalAction: String, Codable {
case openDirectory /// Opens the target directory.

var description: String {
switch self {
case .openDirectory: return "openDirectory"
}
}
}
37 changes: 10 additions & 27 deletions surmagic/Sources/surmagic/Surfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ import Foundation
<string>_SCHEME_NAME_HERE_</string>
</dict>
</array>
<key>finalActions</key>
<array>
<string>_ACTION1_</string>
<string>_ACTION2_</string>
<string>_ACTION3_</string>
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>


Expand All @@ -48,7 +46,7 @@ import Foundation
"workspace": "_WORKSPACE_NAME_HERE_.xcworkspace",
"scheme": "_SCHEME_NAME_HERE_"
}],
"finalActions": ["_ACTION1_,_ACTION2_,_ACTION3_"]
"finalActions": ["openDirectory"]
}

> as a File form.
Expand All @@ -74,12 +72,10 @@ import Foundation
<string>_SCHEME_NAME_HERE_</string>
</dict>
</array>
<key>finalActions</key>
<array>
<string>_ACTION1_</string>
<string>_ACTION2_</string>
<string>_ACTION3_</string>
</array>
<key>finalActions</key>
<array>
<string>openDirectory</string>
</array>
</dict>
</plist>

Expand All @@ -88,19 +84,6 @@ import Foundation
/// Content of the Surfile.
public class Surfile: Codable {

// MARK: - Enums

/// FinalAction
public enum FinalAction: String, Codable {
case openDirectory /// Opens the target directory.

var description: String {
switch self {
case .openDirectory: return "openDirectory"
}
}
}

// MARK: - Properties

/// output_path specifies the directory where any created archives will be placed,
Expand All @@ -116,7 +99,7 @@ public class Surfile: Codable {

/// Final actions after finishing the work. If it's empty, no action will take by the system.
/// - @usage: ["openDirectory", ...etc]
let finalActions: [FinalAction]? = []
let finalActions: [FinalAction]?

public var desc: String {
var result = (
Expand Down
10 changes: 7 additions & 3 deletions surmagic/Sources/surmagic/XCFCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public class XCFCommand {
</array>
<key>finalActions</key>
<array>
<string>_ACTION1_</string>
<string>_ACTION2_</string>
<string>_ACTION3_</string>
<string>openDirectory</string>
</array>
</dict>
</plist>
Expand Down Expand Up @@ -143,11 +141,17 @@ public class XCFCommand {
private func runFinalActions(_ surfile: Surfile) {
if let finalActions = surfile.finalActions {
for action in finalActions {
let message = "\n ⚪️ Action: \(action)\n"
SurmagicHelper.shared.writeLine(message, inColor: .cyan, bold: false)

switch action {
case .openDirectory:
openOutputPath(surfile.output_path)
}
}
} else {
let message = "\n 🏁 No Final Actions to run\n"
SurmagicHelper.shared.writeLine(message, inColor: .green, bold: false)
}
}

Expand Down

0 comments on commit 48f78d4

Please sign in to comment.