Skip to content

Commit f0eeaba

Browse files
committed
kebab-case options
1 parent d30c94b commit f0eeaba

File tree

5 files changed

+58
-34
lines changed

5 files changed

+58
-34
lines changed

CommandLine/CommandLine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ Options:
8383
--precision maximum number of decimal places
8484
--output optional path of output file
8585
86-
--hideUnsupportedFilters hide elements with unsupported filters.
86+
--hide-unsupported-filters hide elements with unsupported filters.
8787
8888
Available keys for --format swift:
8989
--api api of generated code: appkit | uikit
9090
9191
Available keys for --format sfsymbol:
9292
--insets alignment of regular variant: top,left,bottom,right | auto
9393
--ultralight svg file of ultralight variant
94-
--ultralightInsets alignment of ultralight variant: top,left,bottom,right | auto
94+
--ultralight-insets alignment of ultralight variant: top,left,bottom,right | auto
9595
--black svg file of black variant
96-
--blackInsets alignment of black variant: top,left,bottom,right | auto
96+
--black-insets alignment of black variant: top,left,bottom,right | auto
9797
--legacy use the original, less precise alignment logic from earlier swiftdraw versions.
9898
9999

SwiftDraw/Sources/CommandLine/CommandLine.Arguments.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ extension CommandLine {
5656
return true
5757
}
5858
}
59+
60+
static func make(from text: String) -> Self? {
61+
if let modifier = Modifier(rawValue: text) {
62+
return modifier
63+
}
64+
65+
switch text {
66+
case "ultralight-insets":
67+
return .ultralightInsets
68+
case "black-insets":
69+
return .blackInsets
70+
case "hide-unsupported-filters":
71+
return .hideUnsupportedFilters
72+
default:
73+
return nil
74+
}
75+
}
5976
}
6077

6178
static func parseModifiers(from args: [String]) throws -> [Modifier: String?] {
@@ -91,7 +108,7 @@ private extension Array where Element == String {
91108
}
92109

93110
guard self[0].hasPrefix("--"),
94-
let modifier = CommandLine.Modifier(rawValue: String(self[0].dropFirst(2))) else {
111+
let modifier = CommandLine.Modifier.make(from: String(self[0].dropFirst(2))) else {
95112
throw CommandLine.Error.invalid
96113
}
97114

SwiftDraw/Sources/CommandLine/CommandLine.Configuration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension CommandLine {
110110
let size = try parseSize(from: modifiers[.size])
111111
let scale = try parseScale(from: modifiers[.scale])
112112
let precision = try parsePrecision(from: modifiers[.precision])
113-
let insets = try parseInsets(from: modifiers[.insets])
113+
let insets = try parseInsets(from: modifiers[.insets]) ?? Insets()
114114
let api = try parseAPI(from: modifiers[.api])
115115
let ultralight = try parseFileURL(file: modifiers[.ultralight], within: baseDirectory)
116116
let ultralightInsets = try parseInsets(from: modifiers[.ultralightInsets])
@@ -208,11 +208,11 @@ extension CommandLine {
208208
return api
209209
}
210210

211-
static func parseInsets(from value: String??) throws -> Insets {
211+
static func parseInsets(from value: String??) throws -> Insets? {
212212
guard let value = value,
213213
let value = value,
214214
value != "auto" else {
215-
return Insets()
215+
return nil
216216
}
217217

218218
var scanner = XMLParser.Scanner(text: value)

SwiftDraw/Sources/Renderer/Renderer.SFSymbol.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extension SFSymbolRenderer {
144144
}
145145

146146
func makeBounds(svg: DOM.SVG, isRegularSVG: Bool = true, auto: LayerTree.Rect, for variant: Variant) throws -> LayerTree.Rect {
147-
let insets = getInsets(for: isRegularSVG ? .regular : variant)
147+
let insets = getInsets(for: variant)
148148
let width = LayerTree.Float(svg.width)
149149
let height = LayerTree.Float(svg.height)
150150
let top = insets.top ?? Double(auto.minY)
@@ -337,9 +337,9 @@ extension SFSymbolRenderer {
337337
case .regular:
338338
print("Alignment: --insets \(top),\(left),\(bottom),\(right)")
339339
case .ultralight:
340-
print("Alignment: --ultralightInsets \(top),\(left),\(bottom),\(right)")
340+
print("Alignment: --ultralight-insets \(top),\(left),\(bottom),\(right)")
341341
case .black:
342-
print("Alignment: --blackInsets \(top),\(left),\(bottom),\(right)")
342+
print("Alignment: --black-insets \(top),\(left),\(bottom),\(right)")
343343
}
344344
}
345345

SwiftDraw/Tests/CommandLine/CommandLine.ArgumentsTests.swift

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,36 @@ import XCTest
3434

3535
final class CommandLineArgumentsTests: XCTestCase {
3636

37-
func testParseModifiers() throws {
38-
let modifiers = try CommandLine.parseModifiers(from: ["--format", "some", "--output", "more", "--scale", "magnify", "--size", "huge"])
39-
XCTAssertEqual(modifiers, [.format: "some", .output: "more", .scale: "magnify", .size: "huge"])
40-
}
41-
42-
func testParseModifiersThrowsForOddPairs() {
43-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format"]))
44-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--output"]))
45-
}
46-
47-
func testParseModifiersThrowsForDuplicateModifiers() {
48-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--format", "jpg"]))
49-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--output", "more", "--output", "evenmore"]))
50-
}
51-
52-
func testParseModifiersThrowsForUnknownModifiers() {
53-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--unknown", "png"]))
54-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--unknown", "more"]))
55-
}
56-
57-
func testParseModifiersThrowsForMissingPrefix() {
58-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["format", "png"]))
59-
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "output", "more"]))
60-
}
37+
func testParseModifiers() throws {
38+
var modifiers = try CommandLine.parseModifiers(from: ["--format", "some", "--output", "more", "--scale", "magnify", "--size", "huge"])
39+
XCTAssertEqual(modifiers, [.format: "some", .output: "more", .scale: "magnify", .size: "huge"])
40+
41+
modifiers = try CommandLine.parseModifiers(from: ["--ultralightInsets", "a", "--blackInsets", "b", "--hideUnsupportedFilters", "--legacy"])
42+
XCTAssertEqual(modifiers, [.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil])
43+
44+
modifiers = try CommandLine.parseModifiers(from: ["--ultralight-insets", "a", "--black-insets", "b", "--hide-unsupported-filters", "--legacy"])
45+
XCTAssertEqual(modifiers, [.ultralightInsets: "a", .blackInsets: "b", .hideUnsupportedFilters: nil, .legacy: nil])"
46+
47+
}
48+
49+
func testParseModifiersThrowsForOddPairs() {
50+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format"]))
51+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--output"]))
52+
}
53+
54+
func testParseModifiersThrowsForDuplicateModifiers() {
55+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--format", "jpg"]))
56+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--output", "more", "--output", "evenmore"]))
57+
}
58+
59+
func testParseModifiersThrowsForUnknownModifiers() {
60+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--unknown", "png"]))
61+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "--unknown", "more"]))
62+
}
63+
64+
func testParseModifiersThrowsForMissingPrefix() {
65+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["format", "png"]))
66+
XCTAssertThrowsError(try CommandLine.parseModifiers(from: ["--format", "png", "output", "more"]))
67+
}
6168

6269
}

0 commit comments

Comments
 (0)