Closed tperfitt closed 1 year ago
Hi @tperfitt, thanks for the PR. There's a lot to unpack, so here goes!
https://github.com/ninxsoft/Mist/blob/e5545a07489bffdf24beb55c578925d4223f67ac/Mist/Commands/Download/Download.swift#L26-L31
I don't believe this is an error - the command is running successfully and not finding a result from Apple. If there is an error retrieving results from Apple, a separate MistError
is thrown.
Looks good, I would just update the variable name + description from:
To:
@Flag(name: .shortAndLong, help: """
Print output in JSON format for structured parsing.
""")
var jsonOutput: Bool = false
To help reduce duplication of code, we can add a helper function to Dictionary+Extension.swift:
func jsonString() -> String? {
do {
let data: Data = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted)
return String(data: data, encoding: .utf8)
} catch {
Swift.print(error.localizedDescription)
return nil
}
}
This will allow us to convert any valid dictionary to a JSON string. We can then cleanup the method that prints headers from:
To:
static func printHeader(_ header: String, jsonOutput: Bool) {
var string: String = ""
if jsonOutput {
let dictionary: [String: String] = ["Header": header]
if let jsonString: String = dictionary.jsonString() {
string = jsonString
}
} else {
let horizontal: String = String(repeating: "─", count: header.count + 2)
string = "┌\(horizontal)┐\n│ \(header) │\n└\(horizontal)┘"
}
Swift.print(string)
}
For the non-header printing method, the method signature is getting a little out of control:
structuredOutput: false
in both HTTP.swift and List.swift. To promote feature parity, I would look at adding jsonOutput
to ListOptions, and passing on this value to HTTP methods from either ListOptions
or DownloadOptions
.messagetype: String
to a MessageType
enumLooks good to me!
Looks good to me, and thanks!
I am not sold on the idea of repurposing stderr
to filter out header + info messages. In my head, stderr
should be used for errors, and errors alone. By adding structured JSON output, do we not have a way to filter out / parse stdout
messages we do not care about?
mist
originally only supported macOS Installers, and Firmware support was added as an afterthought. Since there is a lot of overlap, it probably makes sense to create a DownloadInfo
(can't think of a better name 🤔) protocol, of which both the Firmware
and Product
structs conform to.
Alternatively, if it feels like too much work (and macOS Installers will eventually be phased out in favour of Firmwares...), we can leave it just the way it is 🙃.
Additionally, there are a couple of housekeeping tasks that have crept into your PR:
Are you able to roll these back to 7K3HVCLV7Z
?
Your PR in it's current form will fail to merge as it does not pass all linting checks. SwiftLint can be installed and run manually with swiftlint --strict
from the root of the project. There is also a Run SwiftLint script phase as part of the Xcode project build process:
if which swiftlint > /dev/null ; then
swiftlint --strict
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
exit 0
Note: The linting rules I enforce are quite strict 😅.
The same goes for docstrings - I use DrString to ensure docstrings are consistent. You can run manually with drstring check --config-file .drstring.toml
from the root of the project, or via the Run DrString script phase as part of the Xcode project build process:
if which drstring > /dev/null ; then
drstring check --config-file "$SRCROOT/.drstring.toml" || true
else
echo "warning: DrString not installed, download from https://github.com/dduan/DrString"
fi
exit 0
Closing due to inactivity, will re-open if required by @tperfitt 👍
I incorporated Mist into MDS and it has been working great! I wanted to have a more structured output for easy parsing from MDS so I added in some changes: