Skip to content

Commit

Permalink
cleanup docs, align API
Browse files Browse the repository at this point in the history
  • Loading branch information
heckj committed Dec 29, 2024
1 parent 1082b03 commit f537c1a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 63 deletions.
8 changes: 2 additions & 6 deletions Sources/Formic/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ Quite a is inspired by [Ansible](https://github.com/ansible/ansible), with a goa

### Running Playbooks

- ``Playbook``
- ``Engine``
- ``PlaybookStatus``
- ``PlaybookState``
- ``CommandExecutionResult``
- ``Verbosity``

Expand All @@ -41,7 +38,7 @@ Quite a is inspired by [Ansible](https://github.com/ansible/ansible), with a goa
### Resources

- ``OperatingSystem``
- ``DebianPackage``
- ``Dpkg``

- ``Resource``
- ``StatefulResource``
Expand All @@ -52,5 +49,4 @@ Quite a is inspired by [Ansible](https://github.com/ansible/ansible), with a goa

### Collections of Resources

- ``CollectionQueryableResource``
- ``NamedResource``
- ``CollectionResource``
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

- ``command``
- ``host``
- ``playbookId``
- ``output``
- ``duration``
- ``retries``
Expand Down
18 changes: 6 additions & 12 deletions Sources/Formic/Documentation.docc/Engine/Engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@

### Running Playbooks

- ``schedule(_:delay:startRunner:)``
- ``step(for:)``
- ``cancel(_:)``
- ``run(host:commands:displayProgress:verbosity:)``
- ``run(hosts:commands:displayProgress:verbosity:)``

### Receiving Updates from the Engine

- ``commandUpdates``
- ``playbookUpdates``
- ``status(_:)``
### Running an individual command

### Inspecting the Engine
- ``run(host:command:)``

- ``runnerOperating(for:)``
### Receiving Updates from the Engine

### Controlling the Engine
- ``commandUpdates``

- ``cancelRunner(for:)``
11 changes: 0 additions & 11 deletions Sources/Formic/Documentation.docc/Engine/PlaybookState.md

This file was deleted.

9 changes: 0 additions & 9 deletions Sources/Formic/Documentation.docc/Engine/PlaybookStatus.md

This file was deleted.

15 changes: 0 additions & 15 deletions Sources/Formic/Documentation.docc/Playbook.md

This file was deleted.

1 change: 0 additions & 1 deletion Sources/Formic/Engine/CommandExecutionResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public struct CommandExecutionResult: Sendable {
/// - Parameters:
/// - command: The command.
/// - host: The host for the command.
/// - playbookId: The ID of the playbook the command is part of, it any.
/// - output: The output from the command
/// - duration: The duration of execution of the command.
/// - retries: The number of retries needed for the command.
Expand Down
9 changes: 4 additions & 5 deletions Sources/Formic/Engine/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public actor Engine {
) async throws -> [CommandExecutionResult] {
var results: [CommandExecutionResult] = []
for command in commands {
let result = try await run(command: command, host: host)
let result = try await run(host: host, command: command)
results.append(result)
if displayProgress {
print(result.consoleOutput(verbosity: verbosity))
Expand Down Expand Up @@ -67,13 +67,12 @@ public actor Engine {
return hostResults
}

/// Directly runs a single command against a single host.
/// Directly runs a single command against a single host, applying the retry and timeout policies of the command.
/// - Parameters:
/// - command: The command to run.
/// - host: The host on which to run the command.
/// - playbookId: The ID of the playbook the command is part of.
/// - command: The command to run.
/// - Returns: The result of the command execution.
public nonisolated func run(command: (any Command), host: Host) async throws
public nonisolated func run(host: Host, command: (any Command)) async throws
-> CommandExecutionResult
{
// `nonisolated` + `async` means run on a cooperative thread pool and return the result
Expand Down
2 changes: 2 additions & 0 deletions Sources/Formic/ResourceTypes/Dpkg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public struct Dpkg: Sendable, Hashable, Resource {
/// - Parameters:
/// - name: The name of the package.
/// - state: The desired state of the package.
/// - retry: The retry settings for resolving the resource.
/// - resolveTimeout: The execution timeout to allow the resource to resolve.
public init(
name: String, state: DesiredPackageState, retry: Backoff = .never, resolveTimeout: Duration = .seconds(60)
) {
Expand Down
6 changes: 3 additions & 3 deletions Tests/formicTests/EngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func testEngineRun() async throws {
dependencyValues.commandInvoker = TestCommandInvoker()
.addSuccess(command: ["uname"], presentOutput: "Darwin\n")
} operation: {
try await engine.run(command: cmd, host: .localhost)
try await engine.run(host: .localhost, command: cmd)
}

#expect(cmdExecOut.command.id == cmd.id)
Expand Down Expand Up @@ -172,7 +172,7 @@ func testCommandTimeout() async throws {
dependencyValues.localSystemAccess = TestFileSystemAccess()
dependencyValues.commandInvoker = mockCmdInvoker
} operation: {
return try await engine.run(command: cmd1, host: fakeHost)
return try await engine.run(host: fakeHost, command: cmd1)
}
})
}
Expand All @@ -197,7 +197,7 @@ func testCommandRetry() async throws {
dependencyValues.localSystemAccess = TestFileSystemAccess()
dependencyValues.commandInvoker = mockCmdInvoker
} operation: {
return try await engine.run(command: cmd1, host: fakeHost)
return try await engine.run(host: fakeHost, command: cmd1)
}

#expect(result.command.id == cmd1.id)
Expand Down

0 comments on commit f537c1a

Please sign in to comment.