Skip to content

Commit 5574283

Browse files
committed
fix: improve argument handling
1 parent fbefeec commit 5574283

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

Sources/JsonScripts.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ArgumentParser
22
import Figlet
33
import Foundation
44

5-
let VERSION = "0.1.0"
5+
let VERSION = "0.1.1"
66

77
struct KeyValueOption: ExpressibleByArgument {
88
let key: String
@@ -98,11 +98,14 @@ struct JsonScripts: ParsableCommand {
9898
commandStr = definition.replaceVars(commandStr, variables: vars)
9999

100100
if !arguments.isEmpty {
101-
var joinedArgs = arguments.joined(separator: " ")
102-
103-
if joinedArgs.hasPrefix("{") && joinedArgs.hasSuffix("}") || joinedArgs.hasPrefix("[") && joinedArgs.hasSuffix("]") {
104-
joinedArgs = "'\(joinedArgs)'"
105-
}
101+
let joinedArgs = arguments.map({ arg in
102+
if arg.hasPrefix("{") && arg.hasSuffix("}")
103+
|| arg.hasPrefix("[") && arg.hasSuffix("]")
104+
{
105+
return "'\(arg)'"
106+
}
107+
return arg
108+
}).joined(separator: " ")
106109

107110
commandStr += " " + joinedArgs
108111
}

Sources/Shell.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,20 @@ func shellProcess(_ commandStr: String) throws {
4545
}
4646

4747
func bashEscape(_ input: String) -> String {
48-
var escaped = ""
49-
for char in input {
50-
switch char {
51-
case "\\":
52-
escaped.append("\\\\")
53-
case "\"":
54-
escaped.append("\\\"")
55-
case "$":
56-
escaped.append("\\$")
57-
case "`":
58-
escaped.append("\\`")
59-
default:
60-
escaped.append(char)
61-
}
48+
var escaped = ""
49+
for char in input {
50+
switch char {
51+
case "\\":
52+
escaped.append("\\\\")
53+
case "\"":
54+
escaped.append("\\\"")
55+
case "$":
56+
escaped.append("\\$")
57+
case "`":
58+
escaped.append("\\`")
59+
default:
60+
escaped.append(char)
6261
}
63-
return escaped
62+
}
63+
return escaped
6464
}
65-

0 commit comments

Comments
 (0)