Skip to content

Commit 662c84a

Browse files
committed
Update new api
1 parent 90ce501 commit 662c84a

35 files changed

Lines changed: 769 additions & 365 deletions

Package.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ let package = Package(
1313
.library(name: "Core", targets: ["Core"]),
1414
.library(name: "Github", targets: ["Github"])
1515
],
16-
dependencies: [
17-
.package(url: "https://github.com/asielcabrera/Terminal.git", from: "0.0.1"),
18-
],
16+
dependencies: [],
1917
targets: [
2018

2119
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -25,11 +23,11 @@ let package = Package(
2523
dependencies: ["Core", "Github"]),
2624
.target(
2725
name: "Core",
28-
dependencies: ["Terminal"]
26+
dependencies: []
2927
),
3028
.target(
3129
name: "Github",
32-
dependencies: ["Terminal"]
30+
dependencies: []
3331
),
3432
.testTarget(
3533
name: "Github-toolkitTests",

Sources/Core/CommandName.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// CommandProperties.swift
3+
//
4+
//
5+
// Created by Asiel Cabrera Gonzalez on 9/9/23.
6+
//
7+
8+
// For internal use, subject to change.
9+
// We use Any as a valid input type
10+
11+
public struct CommandProperties {
12+
var properties: [String: Any]
13+
14+
public init(_ properties: [String: Any]) {
15+
self.properties = properties
16+
}
17+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// Commands.swift
3+
//
4+
//
5+
// Created by Asiel Cabrera Gonzalez on 9/9/23.
6+
//
7+
8+
import Foundation
9+
10+
11+
/**
12+
Commands
13+
Command Format:
14+
::name key=value,key=value::message
15+
Examples:
16+
::warning::This is the message
17+
::set-env name=MY_VAR::some value
18+
*/
19+
20+
21+
public struct Command<T>: CustomStringConvertible {
22+
private let CMD_STRING = "::"
23+
private let command: String
24+
private let message: T
25+
private let properties: CommandProperties
26+
27+
init(_ command: String, _ properties: CommandProperties, _ message: T) {
28+
self.command = command.isEmpty ? "missing.command" : command
29+
self.properties = properties
30+
self.message = message
31+
}
32+
33+
public var description: String {
34+
var cmdStr = CMD_STRING + command
35+
36+
if !properties.properties.isEmpty {
37+
cmdStr += " "
38+
var first = true
39+
for (key, val) in properties.properties {
40+
if first {
41+
first = false
42+
} else {
43+
cmdStr += ","
44+
}
45+
cmdStr += "\(key)=\(escapeProperty(val as! T))"
46+
}
47+
}
48+
49+
cmdStr += "\(CMD_STRING)\(escapeData(message))"
50+
return cmdStr
51+
}
52+
53+
private func escapeData(_ value: T) -> String {
54+
return toCommandValue(value)
55+
.replacingOccurrences(of: "%", with: "%25")
56+
.replacingOccurrences(of: "\r", with: "%0D")
57+
.replacingOccurrences(of: "\n", with: "%0A")
58+
}
59+
60+
private func escapeProperty(_ value: T) -> String {
61+
return toCommandValue(value)
62+
.replacingOccurrences(of: "%", with: "%25")
63+
.replacingOccurrences(of: "\r", with: "%0D")
64+
.replacingOccurrences(of: "\n", with: "%0A")
65+
.replacingOccurrences(of: ":", with: "%3A")
66+
.replacingOccurrences(of: ",", with: "%2C")
67+
}
68+
69+
private func toCommandValue(_ value: T) -> String {
70+
return String(describing: value)
71+
}
72+
}

Sources/Core/Commands/Debug.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Sources/Core/Commands/Failures.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

Sources/Core/Commands/Inputs.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

Sources/Core/Commands/Outputs.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Sources/Core/Commands/Protocols/CommandProtocol.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

Sources/Core/Commands/Protocols/EchoCommandProtocol.swift

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)