mirror of
https://github.com/nsomar/Swiftline.git
synced 2024-09-11 05:35:42 +03:00
Updating static functions to static variables
This commit is contained in:
parent
710beb92ae
commit
cc7a52279e
@ -10,13 +10,13 @@
|
||||
|
||||
public class Args {
|
||||
|
||||
public static func all() -> [String] {
|
||||
public static var all: [String] {
|
||||
return ProcessInfo.arguments
|
||||
}
|
||||
|
||||
public static func args() -> ParsedArgs {
|
||||
public static var parsed: ParsedArgs {
|
||||
var result = [String: String]()
|
||||
let parsedArges = ArgsParser.parseFlags(all())
|
||||
let parsedArges = ArgsParser.parseFlags(all)
|
||||
|
||||
parsedArges.0.forEach {
|
||||
result[$0.argument.name] = $0.value ?? ""
|
||||
@ -28,6 +28,6 @@ public class Args {
|
||||
|
||||
|
||||
public struct ParsedArgs {
|
||||
let flags: [String: String]
|
||||
let parameters: [String]
|
||||
public let flags: [String: String]
|
||||
public let parameters: [String]
|
||||
}
|
@ -8,6 +8,16 @@
|
||||
|
||||
public class Env {
|
||||
|
||||
public static var keys: [String] {
|
||||
let keyValues = run("env").stdout.componentsSeparatedByString("\n")
|
||||
let keys = keyValues.map { $0.componentsSeparatedByString("=").first! }.filter { !$0.isEmpty }
|
||||
return keys
|
||||
}
|
||||
|
||||
public static var values: [String] {
|
||||
return self.keys.map { self.get($0)! }
|
||||
}
|
||||
|
||||
public static func get(key: String) -> String? {
|
||||
let value = getenv(key)
|
||||
return String.fromCString(value)
|
||||
@ -22,32 +32,22 @@ public class Env {
|
||||
}
|
||||
|
||||
public static func clear() {
|
||||
self.keys()
|
||||
self.keys
|
||||
.map { String($0) }
|
||||
.filter { $0 != nil }
|
||||
.forEach{ self.set($0!, nil) }
|
||||
}
|
||||
|
||||
public static func keys() -> [String] {
|
||||
let keyValues = run("env").stdout.componentsSeparatedByString("\n")
|
||||
let keys = keyValues.map { $0.componentsSeparatedByString("=").first! }.filter { !$0.isEmpty }
|
||||
return keys;
|
||||
}
|
||||
|
||||
public static func values() -> [String] {
|
||||
return self.keys().map { self.get($0)! }
|
||||
}
|
||||
|
||||
public static func hasKey(key: String) -> Bool {
|
||||
return self.keys().contains(key)
|
||||
return self.keys.contains(key)
|
||||
}
|
||||
|
||||
public static func hasValue(value: String) -> Bool {
|
||||
return self.values().contains(value)
|
||||
return self.values.contains(value)
|
||||
}
|
||||
|
||||
public static func eachPair(callback: (key: String, value: String) -> ()) {
|
||||
zip(self.keys(), self.values()).forEach(callback)
|
||||
zip(self.keys, self.values).forEach(callback)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,12 +9,12 @@ class ArgsTests: QuickSpec {
|
||||
describe("Args") {
|
||||
|
||||
it("returns the correct number of args passed") {
|
||||
expect(Args.all().count).to(beGreaterThan(0))
|
||||
expect(Args.all.count).to(beGreaterThan(0))
|
||||
}
|
||||
|
||||
it("returns the exact argument passed to the app") {
|
||||
ProcessInfo.internalProcessInfo = DummyProcessInfo("1", "2", "3")
|
||||
expect(Args.all()).to(equal(["1", "2", "3"]))
|
||||
expect(Args.all).to(equal(["1", "2", "3"]))
|
||||
}
|
||||
|
||||
it("creats a hash from passed args") {
|
||||
@ -24,8 +24,8 @@ class ArgsTests: QuickSpec {
|
||||
"integer": "1",
|
||||
"no-ff": ""]
|
||||
|
||||
expect(Args.args().flags).to(equal(result))
|
||||
expect(Args.args().parameters).to(equal(["Some custom one", "one", "two"]))
|
||||
expect(Args.parsed.flags).to(equal(result))
|
||||
expect(Args.parsed.parameters).to(equal(["Some custom one", "one", "two"]))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,9 @@ class ENVTests: QuickSpec {
|
||||
Env.set("key1", "value1")
|
||||
Env.set("key2", "value2")
|
||||
|
||||
expect(Env.keys()).to(equal(["key1", "key2"]))
|
||||
expect(Env.keys).to(equal(["key1", "key2"]))
|
||||
Env.clear()
|
||||
expect(Env.keys().count).to(equal(0))
|
||||
expect(Env.keys.count).to(equal(0))
|
||||
}
|
||||
|
||||
it("return all values") {
|
||||
@ -53,7 +53,7 @@ class ENVTests: QuickSpec {
|
||||
Env.set("key1", "value1")
|
||||
Env.set("key2", "value2")
|
||||
|
||||
expect(Env.values()).to(equal(["value1", "value2"]))
|
||||
expect(Env.values).to(equal(["value1", "value2"]))
|
||||
}
|
||||
|
||||
it("checks if key exists") {
|
||||
|
Loading…
Reference in New Issue
Block a user