-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2/2 Add
--json
flag to list-*
query commands
- Loading branch information
1 parent
0d71278
commit d914e20
Showing
20 changed files
with
233 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Common | ||
import Foundation | ||
|
||
extension [AeroObj] { | ||
func formatToJson(_ format: [StringInterToken], ignoreRightPaddingVar: Bool) -> Result<String, String> { | ||
var list: [[String: Primitive]] = [] | ||
for richObj in self { | ||
var rawObj: [String: Primitive] = [:] | ||
for token in format { | ||
switch token { | ||
case .value("right-padding") where ignoreRightPaddingVar: | ||
break | ||
case .literal: | ||
break // should be spaces | ||
case .value(let varName): | ||
switch varName.expandFormatVar(obj: richObj) { | ||
case .success(let expanded): rawObj[varName] = expanded | ||
case .failure(let error): return .failure(error) | ||
} | ||
} | ||
} | ||
list.append(rawObj) | ||
} | ||
return JSONEncoder.aeroSpaceDefault.encodeToString(list).map(Result.success) | ||
?? .failure("Can't encode '\(list)' to JSON") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
extension JSONEncoder { | ||
static var aeroSpaceDefault: JSONEncoder { | ||
let encoder = JSONEncoder() | ||
encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes] | ||
return encoder | ||
} | ||
|
||
func encodeToString(_ value: Encodable) -> String? { | ||
guard let data = Result(catching: { try encode(value) }).getOrNil() else { return nil } | ||
return String(data: data, encoding: .utf8) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.