@@ -14,27 +14,14 @@ import Markdown
14
14
15
15
@main
16
16
struct MarkdownCommand : ParsableCommand {
17
- enum Error : LocalizedError {
18
- case couldntDecodeInputAsUTF8
19
-
20
- var errorDescription : String ? {
21
- switch self {
22
- case . couldntDecodeInputAsUTF8:
23
- return " Couldn't decode input as UTF-8 "
24
- }
25
- }
26
- }
27
-
28
17
static let configuration = CommandConfiguration ( commandName: " markdown " , shouldDisplay: false , subcommands: [
29
18
DumpTree . self,
30
19
Format . self,
31
20
] )
32
21
33
22
static func parseFile( at path: String , options: ParseOptions ) throws -> ( source: String , parsed: Document ) {
34
23
let data = try Data ( contentsOf: URL ( fileURLWithPath: path) )
35
- guard let inputString = String ( data: data, encoding: . utf8) else {
36
- throw Error . couldntDecodeInputAsUTF8
37
- }
24
+ let inputString = String ( decoding: data, as: UTF8 . self)
38
25
return ( inputString, Document ( parsing: inputString, options: options) )
39
26
}
40
27
@@ -45,9 +32,7 @@ struct MarkdownCommand: ParsableCommand {
45
32
} else {
46
33
stdinData = FileHandle . standardInput. readDataToEndOfFile ( )
47
34
}
48
- guard let stdinString = String ( data: stdinData, encoding: . utf8) else {
49
- throw Error . couldntDecodeInputAsUTF8
50
- }
35
+ let stdinString = String ( decoding: stdinData, as: UTF8 . self)
51
36
return ( stdinString, Document ( parsing: stdinString, options: options) )
52
37
}
53
38
}
0 commit comments