@lewishowles/cli-style 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.8.0 - 2026-07-05
6
+
7
+ ### Added
8
+
9
+ - Added Swift adapter with convenience functions for scalar primitives and per-script patterns: `CliStyle.status`, `CliStyle.row`, `CliStyle.span`, `CliStyle.hint`, `CliStyle.divider`, `CliStyle.commandResult`, `CliStyle.auditFinding`, `CliStyle.taskSummary`, `CliStyle.confirmationResult`, and `CliStyle.nextStepBlock`.
10
+ - Added `cli-style adapter-path swift` support for discovering the Swift adapter file path.
11
+
12
+ ### Changed
13
+
14
+ - Extended the README renderer table with a Swift helper column covering all 20 renderers.
15
+
3
16
  ## 0.7.0 - 2026-07-05
4
17
 
5
18
  ### Added
package/README.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Shared terminal output styles for local tools, diagnostics, agent-facing reports, and package CLIs.
4
4
 
5
- Use it directly from JavaScript, or call the same renderers from Bash and Python through the `cli-style` binary.
5
+ Use it directly from JavaScript, or call the same renderers from Bash, Python, and Swift through the `cli-style` binary.
6
6
 
7
7
  ## Requirements
8
8
 
9
9
  - Bun and Node.js 20 or newer for JavaScript projects and local binary builds
10
- - The standalone `cli-style` binary for Bash or Python projects that should not install Bun
10
+ - The standalone `cli-style` binary for Bash, Python, or Swift projects that should not install Bun
11
11
 
12
12
  ## Install
13
13
 
@@ -17,7 +17,7 @@ JavaScript projects can install the package directly:
17
17
  bun add @lewishowles/cli-style
18
18
  ```
19
19
 
20
- Bash and Python projects call the `cli-style` binary through thin adapters. If the project already has Node or Bun tooling, add this package as a dev dependency and use the package binary. Otherwise, install or vendor the standalone binary and put it on `PATH`:
20
+ Bash, Python, and Swift projects call the `cli-style` binary through thin adapters. If the project already has Node or Bun tooling, add this package as a dev dependency and use the package binary. Otherwise, install or vendor the standalone binary and put it on `PATH`:
21
21
 
22
22
  ```bash
23
23
  export PATH="/path/to/cli-style/bin:$PATH"
@@ -41,7 +41,7 @@ The package contains `bin/cli-style` and `adapters/`.
41
41
 
42
42
  ## Choose an integration
43
43
 
44
- All renderers return text. JavaScript imports functions directly. CLI, Bash, and Python integrations pass JSON-compatible data to a named renderer.
44
+ All renderers return text. JavaScript imports functions directly. CLI, Bash, Python, and Swift integrations pass JSON-compatible data to a named renderer.
45
45
 
46
46
  ### JavaScript
47
47
 
@@ -169,33 +169,75 @@ output = render(
169
169
  print(output)
170
170
  ```
171
171
 
172
+ ### Swift
173
+
174
+ Add the adapter file to your Swift project, then use the `CliStyle` enum for convenience functions or the generic `render` method:
175
+
176
+ ```bash
177
+ cli-style adapter-path swift
178
+ # Returns the path to CliStyle.swift for inclusion in your project
179
+ ```
180
+
181
+ ```swift
182
+ let options = CliStyleOptions(binary: "./bin/cli-style.js", isPlain: true)
183
+
184
+ print(try CliStyle.status(type: "success", label: "Build passed", detail: "184 tests", options: options))
185
+ print(try CliStyle.row(label: "Workspace", value: "/path/to/project", options: options))
186
+ print(try CliStyle.row(label: "Bundle", value: "over budget", result: "failed", options: options))
187
+ let command = try CliStyle.span(value: "npm run docs:readme", tone: "info", options: options)
188
+ print(try CliStyle.hint(message: "Run " + command + " before release", options: options))
189
+ print(try CliStyle.divider(label: "Project setup", options: options))
190
+
191
+ print(try CliStyle.commandResult(result: "success", summary: "Build passed", command: "bun run test:unit", exitCode: 0, duration: "1.2s", detail: "184 tests", options: options))
192
+ print(try CliStyle.taskSummary(result: "partial", task: "Adopt cli-style", summary: "Wrappers added", completed: "Updated adapter", remaining: "Update scripts", options: options))
193
+ print(try CliStyle.confirmationResult(state: "confirmed", action: "Publish release", item: "v0.6.0", detail: "Tag push starts npm publish", options: options))
194
+ print(try CliStyle.nextStepBlock(nextStep: "Update helpers scripts", reason: "Wrappers are now available", command: "scripts/setup.sh --check", alternative: "", options: options))
195
+ ```
196
+
197
+ Convenience functions build the renderer payload internally, so callers pass plain Swift strings without hand-building JSON.
198
+
199
+ Pass `binary:` in `CliStyleOptions` when `cli-style` is not on `PATH`. The generic `CliStyle.render(_:data:options:)` method remains for aggregate patterns or multi-item fields:
200
+
201
+ ```swift
202
+ let output = try CliStyle.render(
203
+ "diagnostic-report",
204
+ data: [
205
+ "title": "Release checks",
206
+ "checks": [["name": "README", "result": "success"]],
207
+ ],
208
+ options: CliStyleOptions(profile: "diagnostic")
209
+ )
210
+
211
+ print(output)
212
+ ```
213
+
172
214
  ## Available renderers
173
215
 
174
216
  Renderer names are stable for `cli-style render`, `cli_style_render`, and Python `render()`. JavaScript uses camel-case function names.
175
217
 
176
- | Renderer | JavaScript | Bash helper | Python helper | Purpose |
177
- | --------------------- | ------------------------------------- | ------------------------------------ | ---------------------------------- | --------------------------------------------------------------- |
178
- | `status` | `status(resultType, detail, options)` | `cli_style_status type label detail` | `status(type, label, detail)` | Result line with symbol, label, and detail. |
179
- | `row` | `row(label, value, options)` | `cli_style_row label value [result]` | `row(label, value, result)` | Aligned label/value row, optionally marked with a result state. |
180
- | `span` | `span(value, tone, options)` | `cli_style_span value [tone]` | `span(value, tone)` | Inline colour or weight for a word, command, file, or value. |
181
- | `hint` | `hint(message, options)` | `cli_style_hint message` | `hint(message)` | Informational hint line. |
182
- | `divider` | `divider(options)` | `cli_style_divider label` | `divider(label)` | Section divider with an optional label. |
183
- | `command-result` | `commandResult(options)` | `cli_style_command_result ...` | `command_result(...)` | Command execution outcome with exit code and duration. |
184
- | `audit-finding` | `auditFinding(options)` | `cli_style_audit_finding ...` | `audit_finding(...)` | Structured audit finding with evidence and recommendation. |
185
- | `task-summary` | `taskSummary(options)` | `cli_style_task_summary ...` | `task_summary(...)` | Task progress with completed and remaining items. |
186
- | `confirmation-result` | `confirmationResult(options)` | `cli_style_confirmation_result ...` | `confirmation_result(...)` | Confirmation outcome with action and item. |
187
- | `next-step-block` | `nextStepBlock(options)` | `cli_style_next_step_block ...` | `next_step_block(...)` | Next-step guidance with command and alternative. |
188
- | `chip` | `chip(label, tone, options)` | Use `cli_style_render` | Use `render("chip", ...)` | Compact labelled state. |
189
- | `panel` | `panel(options)` | Use `cli_style_render` | Use `render("panel", ...)` | Framed content block for grouped output. |
190
- | `table` | `table(options)` | Use `cli_style_render` | Use `render("table", ...)` | Tabular records with narrow-width fallback. |
191
- | `progress-bar` | `progressBar(options)` | Use `cli_style_render` | Use `render("progress-bar", ...)` | Single progress value with numeric text. |
192
- | `bar-chart` | `barChart(options)` | Use `cli_style_render` | Use `render("bar-chart", ...)` | Multi-row bar chart. |
193
- | `step` | `step(label, state, options)` | Use `cli_style_render` | Use `render("step", ...)` | One workflow step. |
194
- | `step-progress` | `stepProgress(options)` | Use `cli_style_render` | Use `render("step-progress", ...)` | Numbered workflow steps. |
195
- | `empty-state` | `emptyState(title, detail, options)` | Use `cli_style_render` | Use `render("empty-state", ...)` | Empty result message. |
196
- | `error-block` | `errorBlock(title, lines, options)` | Use `cli_style_render` | Use `render("error-block", ...)` | Structured error block. |
197
-
198
- Use `render("<renderer>", data, ...)` for aggregate patterns (`diagnostic-report`, `agent-transcript`, `compact-data-table`) or any renderer with multi-item fields.
218
+ | Renderer | JavaScript | Bash helper | Python helper | Swift helper | Purpose |
219
+ | --------------------- | ------------------------------------- | ------------------------------------ | ---------------------------------- | -------------------------------------- | --------------------------------------------------------------- |
220
+ | `status` | `status(resultType, detail, options)` | `cli_style_status type label detail` | `status(type, label, detail)` | `CliStyle.status(type, label, detail)` | Result line with symbol, label, and detail. |
221
+ | `row` | `row(label, value, options)` | `cli_style_row label value [result]` | `row(label, value, result)` | `CliStyle.row(label, value, result)` | Aligned label/value row, optionally marked with a result state. |
222
+ | `span` | `span(value, tone, options)` | `cli_style_span value [tone]` | `span(value, tone)` | `CliStyle.span(value, tone)` | Inline colour or weight for a word, command, file, or value. |
223
+ | `hint` | `hint(message, options)` | `cli_style_hint message` | `hint(message)` | `CliStyle.hint(message)` | Informational hint line. |
224
+ | `divider` | `divider(options)` | `cli_style_divider label` | `divider(label)` | `CliStyle.divider(label)` | Section divider with an optional label. |
225
+ | `command-result` | `commandResult(options)` | `cli_style_command_result ...` | `command_result(...)` | `CliStyle.commandResult(...)` | Command execution outcome with exit code and duration. |
226
+ | `audit-finding` | `auditFinding(options)` | `cli_style_audit_finding ...` | `audit_finding(...)` | `CliStyle.auditFinding(...)` | Structured audit finding with evidence and recommendation. |
227
+ | `task-summary` | `taskSummary(options)` | `cli_style_task_summary ...` | `task_summary(...)` | `CliStyle.taskSummary(...)` | Task progress with completed and remaining items. |
228
+ | `confirmation-result` | `confirmationResult(options)` | `cli_style_confirmation_result ...` | `confirmation_result(...)` | `CliStyle.confirmationResult(...)` | Confirmation outcome with action and item. |
229
+ | `next-step-block` | `nextStepBlock(options)` | `cli_style_next_step_block ...` | `next_step_block(...)` | `CliStyle.nextStepBlock(...)` | Next-step guidance with command and alternative. |
230
+ | `chip` | `chip(label, tone, options)` | Use `cli_style_render` | Use `render("chip", ...)` | Use `CliStyle.render` | Compact labelled state. |
231
+ | `panel` | `panel(options)` | Use `cli_style_render` | Use `render("panel", ...)` | Use `CliStyle.render` | Framed content block for grouped output. |
232
+ | `table` | `table(options)` | Use `cli_style_render` | Use `render("table", ...)` | Use `CliStyle.render` | Tabular records with narrow-width fallback. |
233
+ | `progress-bar` | `progressBar(options)` | Use `cli_style_render` | Use `render("progress-bar", ...)` | Use `CliStyle.render` | Single progress value with numeric text. |
234
+ | `bar-chart` | `barChart(options)` | Use `cli_style_render` | Use `render("bar-chart", ...)` | Use `CliStyle.render` | Multi-row bar chart. |
235
+ | `step` | `step(label, state, options)` | Use `cli_style_render` | Use `render("step", ...)` | Use `CliStyle.render` | One workflow step. |
236
+ | `step-progress` | `stepProgress(options)` | Use `cli_style_render` | Use `render("step-progress", ...)` | Use `CliStyle.render` | Numbered workflow steps. |
237
+ | `empty-state` | `emptyState(title, detail, options)` | Use `cli_style_render` | Use `render("empty-state", ...)` | Use `CliStyle.render` | Empty result message. |
238
+ | `error-block` | `errorBlock(title, lines, options)` | Use `cli_style_render` | Use `render("error-block", ...)` | Use `CliStyle.render` | Structured error block. |
239
+
240
+ Use `render("<renderer>", data, ...)` (Python) or `CliStyle.render(_:data:options:)` (Swift) for aggregate patterns (`diagnostic-report`, `agent-transcript`, `compact-data-table`) or any renderer with multi-item fields.
199
241
 
200
242
  ## Primitive data shapes
201
243
 
@@ -301,6 +343,8 @@ The Bash adapter also exposes scalar convenience wrappers for per-script usage:
301
343
 
302
344
  Pass an empty string for optional positional fields you want to skip. Use `cli_style_render` or `cli_style_render_json` for aggregate reports, tables, transcripts, and multi-item arrays.
303
345
 
346
+ Swift equivalents are available as `CliStyle.commandResult(...)`, `CliStyle.auditFinding(...)`, `CliStyle.taskSummary(...)`, `CliStyle.confirmationResult(...)`, and `CliStyle.nextStepBlock(...)`. Use `CliStyle.render` for aggregate reports, tables, transcripts, and multi-item arrays.
347
+
304
348
  ### Pattern example
305
349
 
306
350
  JavaScript:
@@ -488,6 +532,20 @@ Use `createCliStyle()` to resolve these options from `argv`, `env`, `stdout`, CI
488
532
  | `binary` | Path or command name for the `cli-style` binary. |
489
533
  | `extra_args` | Extra CLI arguments to pass through. |
490
534
 
535
+ ### Swift options
536
+
537
+ Swift options are passed via the `CliStyleOptions` struct:
538
+
539
+ | Property | Purpose |
540
+ | ------------- | ------------------------------------------------ |
541
+ | `binary` | Path or command name for the `cli-style` binary. |
542
+ | `profile` | Render with a named profile. |
543
+ | `width` | Override detected output width. |
544
+ | `isPlain` | Disable colour and Unicode decoration. |
545
+ | `isNoColour` | Disable ANSI colour. |
546
+ | `isNoUnicode` | Use ASCII symbols. |
547
+ | `extraArgs` | Extra CLI arguments to pass through. |
548
+
491
549
  ## Profiles
492
550
 
493
551
  | Profile | Behaviour |
@@ -0,0 +1,407 @@
1
+ import Foundation
2
+
3
+ // Error types for cli-style adapter failures.
4
+ enum CliStyleError: Error {
5
+ case notFound(String)
6
+ case renderFailed(String)
7
+ case invalidInput(String)
8
+ }
9
+
10
+ // Options for controlling cli-style render behaviour.
11
+ struct CliStyleOptions {
12
+ // Binary path or command name.
13
+ var binary: String = "cli-style"
14
+
15
+ // Profile name such as human, agent, or json.
16
+ var profile: String? = nil
17
+
18
+ // Terminal width in characters.
19
+ var width: Int? = nil
20
+
21
+ // Force plain text output.
22
+ var isPlain: Bool = false
23
+
24
+ // Disable colour output.
25
+ var isNoColour: Bool = false
26
+
27
+ // Disable Unicode symbols.
28
+ var isNoUnicode: Bool = false
29
+
30
+ // Additional arguments passed through to the binary.
31
+ var extraArgs: [String] = []
32
+ }
33
+
34
+ // Render caller data through the shared cli-style binary.
35
+ enum CliStyle {
36
+
37
+ /**
38
+ Render a dictionary through `cli-style render`.
39
+
40
+ - parameter renderer: Stable renderer name accepted by `cli-style render`.
41
+ - parameter data: JSON-serialisable renderer input.
42
+ - parameter options: Render options including binary path and output flags.
43
+ - returns: Rendered string output from cli-style.
44
+ - throws: `CliStyleError` if the binary is missing, input is invalid, or rendering fails.
45
+ */
46
+ static func render(
47
+ _ renderer: String,
48
+ data: [String: Any],
49
+ options: CliStyleOptions = .init()
50
+ ) throws -> String {
51
+ if renderer.isEmpty {
52
+ throw CliStyleError.invalidInput("renderer must be a non-empty string")
53
+ }
54
+
55
+ let resolvedBinary = try resolveBinary(options.binary)
56
+
57
+ let jsonData: Data
58
+
59
+ do {
60
+ jsonData = try JSONSerialization.data(withJSONObject: data)
61
+ } catch {
62
+ throw CliStyleError.invalidInput("data is not JSON-serialisable")
63
+ }
64
+
65
+ var arguments = ["render", renderer]
66
+
67
+ if let profile = options.profile {
68
+ arguments += ["--profile", profile]
69
+ }
70
+
71
+ if let width = options.width {
72
+ arguments += ["--width", String(width)]
73
+ }
74
+
75
+ if options.isPlain {
76
+ arguments.append("--plain")
77
+ }
78
+
79
+ if options.isNoColour {
80
+ arguments.append("--no-colour")
81
+ }
82
+
83
+ if options.isNoUnicode {
84
+ arguments.append("--no-unicode")
85
+ }
86
+
87
+ arguments += options.extraArgs
88
+
89
+ let process = Process()
90
+ process.executableURL = URL(fileURLWithPath: resolvedBinary)
91
+ process.arguments = arguments
92
+
93
+ let stdinPipe = Pipe()
94
+ let stdoutPipe = Pipe()
95
+ let stderrPipe = Pipe()
96
+ process.standardInput = stdinPipe
97
+ process.standardOutput = stdoutPipe
98
+ process.standardError = stderrPipe
99
+
100
+ do {
101
+ try process.run()
102
+ } catch {
103
+ throw CliStyleError.renderFailed("failed to launch cli-style: \(error.localizedDescription)")
104
+ }
105
+
106
+ stdinPipe.fileHandleForWriting.write(jsonData)
107
+ stdinPipe.fileHandleForWriting.closeFile()
108
+
109
+ process.waitUntilExit()
110
+
111
+ let stdoutData = stdoutPipe.fileHandleForReading.readDataToEndOfFile()
112
+ let stderrData = stderrPipe.fileHandleForReading.readDataToEndOfFile()
113
+
114
+ if process.terminationStatus != 0 {
115
+ let stderrText = String(data: stderrData, encoding: .utf8)?
116
+ .trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
117
+ let message = stderrText.isEmpty
118
+ ? "cli-style render failed with exit code \(process.terminationStatus)"
119
+ : stderrText
120
+
121
+ throw CliStyleError.renderFailed(message)
122
+ }
123
+
124
+ let stdoutText = String(data: stdoutData, encoding: .utf8) ?? ""
125
+ return stdoutText.trimmingCharacters(in: .newlines)
126
+ }
127
+
128
+ /**
129
+ Render a result status line.
130
+
131
+ - parameter type: Result type such as success, failed, warning, or skipped.
132
+ - parameter label: Status label.
133
+ - parameter detail: Optional detail text.
134
+ - parameter options: Render options.
135
+ - returns: Rendered status line.
136
+ - throws: `CliStyleError` on failure.
137
+ */
138
+ static func status(
139
+ type: String,
140
+ label: String = "",
141
+ detail: String = "",
142
+ options: CliStyleOptions = .init()
143
+ ) throws -> String {
144
+ try render("status", data: [
145
+ "type": type,
146
+ "label": label,
147
+ "detail": detail,
148
+ ], options: options)
149
+ }
150
+
151
+ /**
152
+ Render a labelled value row.
153
+
154
+ - parameter label: Row label.
155
+ - parameter value: Row value.
156
+ - parameter result: Optional result type for a symbol and tone.
157
+ - parameter options: Render options.
158
+ - returns: Rendered row line.
159
+ - throws: `CliStyleError` on failure.
160
+ */
161
+ static func row(
162
+ label: String,
163
+ value: String,
164
+ result: String = "",
165
+ options: CliStyleOptions = .init()
166
+ ) throws -> String {
167
+ try render("row", data: [
168
+ "label": label,
169
+ "value": value,
170
+ "result": result,
171
+ ], options: options)
172
+ }
173
+
174
+ /**
175
+ Render an inline span.
176
+
177
+ - parameter value: Span text.
178
+ - parameter tone: Optional colour tone, defaulting to info.
179
+ - parameter options: Render options.
180
+ - returns: Rendered span string.
181
+ - throws: `CliStyleError` on failure.
182
+ */
183
+ static func span(
184
+ value: String,
185
+ tone: String = "info",
186
+ options: CliStyleOptions = .init()
187
+ ) throws -> String {
188
+ try render("span", data: [
189
+ "value": value,
190
+ "tone": tone,
191
+ ], options: options)
192
+ }
193
+
194
+ /**
195
+ Render a divider.
196
+
197
+ - parameter label: Optional divider label.
198
+ - parameter options: Render options.
199
+ - returns: Rendered divider line.
200
+ - throws: `CliStyleError` on failure.
201
+ */
202
+ static func divider(
203
+ label: String = "",
204
+ options: CliStyleOptions = .init()
205
+ ) throws -> String {
206
+ try render("divider", data: [
207
+ "label": label,
208
+ ], options: options)
209
+ }
210
+
211
+ /**
212
+ Render a hint.
213
+
214
+ - parameter message: Hint message.
215
+ - parameter options: Render options.
216
+ - returns: Rendered hint line.
217
+ - throws: `CliStyleError` on failure.
218
+ */
219
+ static func hint(
220
+ message: String,
221
+ options: CliStyleOptions = .init()
222
+ ) throws -> String {
223
+ try render("hint", data: [
224
+ "message": message,
225
+ ], options: options)
226
+ }
227
+
228
+ /**
229
+ Render a command result pattern.
230
+
231
+ - parameter result: Result type such as success, failed, warning, or skipped.
232
+ - parameter summary: Summary line.
233
+ - parameter command: Optional command text.
234
+ - parameter exitCode: Optional integer exit code.
235
+ - parameter duration: Optional duration text.
236
+ - parameter detail: Optional detail line.
237
+ - parameter options: Render options.
238
+ - returns: Rendered command result block.
239
+ - throws: `CliStyleError` on failure.
240
+ */
241
+ static func commandResult(
242
+ result: String,
243
+ summary: String,
244
+ command: String = "",
245
+ exitCode: Int? = nil,
246
+ duration: String = "",
247
+ detail: String = "",
248
+ options: CliStyleOptions = .init()
249
+ ) throws -> String {
250
+ var data: [String: Any] = [
251
+ "result": result,
252
+ "summary": summary,
253
+ "command": command,
254
+ "duration": duration,
255
+ "details": detail.isEmpty ? [] : [detail],
256
+ ]
257
+
258
+ // JSONSerialization needs NSNull for explicit null values.
259
+ if let exitCode = exitCode {
260
+ data["exitCode"] = exitCode
261
+ } else {
262
+ data["exitCode"] = NSNull()
263
+ }
264
+
265
+ return try render("command-result", data: data, options: options)
266
+ }
267
+
268
+ /**
269
+ Render an audit finding pattern.
270
+
271
+ - parameter result: Result type such as success, failed, warning, or skipped.
272
+ - parameter finding: Finding summary.
273
+ - parameter location: Optional source location.
274
+ - parameter recommendation: Optional recommendation text.
275
+ - parameter evidence: Optional evidence line.
276
+ - parameter reference: Optional reference line.
277
+ - parameter options: Render options.
278
+ - returns: Rendered audit finding block.
279
+ - throws: `CliStyleError` on failure.
280
+ */
281
+ static func auditFinding(
282
+ result: String,
283
+ finding: String,
284
+ location: String = "",
285
+ recommendation: String = "",
286
+ evidence: String = "",
287
+ reference: String = "",
288
+ options: CliStyleOptions = .init()
289
+ ) throws -> String {
290
+ try render("audit-finding", data: [
291
+ "result": result,
292
+ "finding": finding,
293
+ "location": location,
294
+ "recommendation": recommendation,
295
+ "evidence": evidence.isEmpty ? [] : [evidence],
296
+ "references": reference.isEmpty ? [] : [reference],
297
+ ], options: options)
298
+ }
299
+
300
+ /**
301
+ Render a task summary pattern.
302
+
303
+ - parameter result: Result type such as success, failed, warning, or skipped.
304
+ - parameter task: Task label.
305
+ - parameter summary: Optional summary detail.
306
+ - parameter completed: Optional completed item.
307
+ - parameter remaining: Optional remaining item.
308
+ - parameter options: Render options.
309
+ - returns: Rendered task summary block.
310
+ - throws: `CliStyleError` on failure.
311
+ */
312
+ static func taskSummary(
313
+ result: String,
314
+ task: String,
315
+ summary: String = "",
316
+ completed: String = "",
317
+ remaining: String = "",
318
+ options: CliStyleOptions = .init()
319
+ ) throws -> String {
320
+ try render("task-summary", data: [
321
+ "result": result,
322
+ "task": task,
323
+ "summary": summary,
324
+ "completed": completed.isEmpty ? [] : [completed],
325
+ "remaining": remaining.isEmpty ? [] : [remaining],
326
+ ], options: options)
327
+ }
328
+
329
+ /**
330
+ Render a confirmation result pattern.
331
+
332
+ - parameter state: Confirmation state such as confirmed, cancelled, or skipped.
333
+ - parameter action: Action label.
334
+ - parameter item: Optional item label.
335
+ - parameter detail: Optional detail text.
336
+ - parameter options: Render options.
337
+ - returns: Rendered confirmation result block.
338
+ - throws: `CliStyleError` on failure.
339
+ */
340
+ static func confirmationResult(
341
+ state: String,
342
+ action: String,
343
+ item: String = "",
344
+ detail: String = "",
345
+ options: CliStyleOptions = .init()
346
+ ) throws -> String {
347
+ try render("confirmation-result", data: [
348
+ "state": state,
349
+ "action": action,
350
+ "item": item,
351
+ "detail": detail,
352
+ ], options: options)
353
+ }
354
+
355
+ /**
356
+ Render a next-step block pattern.
357
+
358
+ - parameter nextStep: Next step text.
359
+ - parameter reason: Optional reason text.
360
+ - parameter command: Optional command line.
361
+ - parameter alternative: Optional alternative line.
362
+ - parameter options: Render options.
363
+ - returns: Rendered next-step block.
364
+ - throws: `CliStyleError` on failure.
365
+ */
366
+ static func nextStepBlock(
367
+ nextStep: String,
368
+ reason: String = "",
369
+ command: String = "",
370
+ alternative: String = "",
371
+ options: CliStyleOptions = .init()
372
+ ) throws -> String {
373
+ try render("next-step-block", data: [
374
+ "next": nextStep,
375
+ "reason": reason,
376
+ "commands": command.isEmpty ? [] : [command],
377
+ "alternatives": alternative.isEmpty ? [] : [alternative],
378
+ ], options: options)
379
+ }
380
+
381
+ /**
382
+ Resolve a command name or executable path for subprocess use.
383
+
384
+ - parameter binary: Binary path or command name.
385
+ - returns: Resolved executable path.
386
+ - throws: `CliStyleError.notFound` if the binary cannot be found.
387
+ */
388
+ static func resolveBinary(_ binary: String) throws -> String {
389
+ if binary.contains("/") {
390
+ if FileManager.default.isExecutableFile(atPath: binary) {
391
+ return binary
392
+ }
393
+ throw CliStyleError.notFound("cli-style binary not found: \(binary)")
394
+ }
395
+
396
+ let path = ProcessInfo.processInfo.environment["PATH"] ?? ""
397
+
398
+ for directory in path.split(separator: ":") {
399
+ let candidate = "\(directory)/\(binary)"
400
+ if FileManager.default.isExecutableFile(atPath: candidate) {
401
+ return candidate
402
+ }
403
+ }
404
+
405
+ throw CliStyleError.notFound("cli-style binary not found: \(binary)")
406
+ }
407
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lewishowles/cli-style",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Shared terminal output styles for Lewis Howles tools, diagnostics, and package CLIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -12,6 +12,10 @@ const adapterPaths = {
12
12
  releasePath: "adapters/python",
13
13
  sourceUrl: new URL("../../adapters/python", import.meta.url),
14
14
  },
15
+ swift: {
16
+ releasePath: "adapters/swift/CliStyle.swift",
17
+ sourceUrl: new URL("../../adapters/swift/CliStyle.swift", import.meta.url),
18
+ },
15
19
  };
16
20
 
17
21
  // Adapter names accepted by the adapter-path command.