feat: Adds minimal cli executable and commands.
All checks were successful
CI / Linux Tests (push) Successful in 6m44s

This commit is contained in:
2026-02-07 21:17:29 -05:00
parent 1a38922ac0
commit 291bed28d5
6 changed files with 103 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
{ {
"originHash" : "b6e6af1076a5bcce49e1231c44be25d770eaef278e2d1ce1c961446d49cb2d00", "originHash" : "9668a267c19bc66e844dc3e46718c4415359171b587f26c2a592bc347bd5446a",
"pins" : [ "pins" : [
{ {
"identity" : "async-http-client", "identity" : "async-http-client",
@@ -172,6 +172,15 @@
"version" : "1.2.1" "version" : "1.2.1"
} }
}, },
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "c5d11a805e765f52ba34ec7284bd4fcd6ba68615",
"version" : "1.7.0"
}
},
{ {
"identity" : "swift-asn1", "identity" : "swift-asn1",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",

View File

@@ -6,6 +6,7 @@ let package = Package(
name: "swift-manual-d", name: "swift-manual-d",
products: [ products: [
.executable(name: "App", targets: ["App"]), .executable(name: "App", targets: ["App"]),
.executable(name: "ductcalc", targets: ["CLI"]),
.library(name: "AuthClient", targets: ["AuthClient"]), .library(name: "AuthClient", targets: ["AuthClient"]),
.library(name: "CSVParser", targets: ["CSVParser"]), .library(name: "CSVParser", targets: ["CSVParser"]),
.library(name: "DatabaseClient", targets: ["DatabaseClient"]), .library(name: "DatabaseClient", targets: ["DatabaseClient"]),
@@ -20,6 +21,7 @@ let package = Package(
.library(name: "ViewController", targets: ["ViewController"]), .library(name: "ViewController", targets: ["ViewController"]),
], ],
dependencies: [ dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.7.0"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.110.1"), .package(url: "https://github.com/vapor/vapor.git", from: "4.110.1"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"), .package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"),
.package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.6.0"), .package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.6.0"),
@@ -54,6 +56,13 @@ let package = Package(
.product(name: "VaporRouting", package: "vapor-routing"), .product(name: "VaporRouting", package: "vapor-routing"),
] ]
), ),
.executableTarget(
name: "CLI",
dependencies: [
.target(name: "ManualDClient"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.target( .target(
name: "AuthClient", name: "AuthClient",
dependencies: [ dependencies: [

14
Sources/CLI/Cli.swift Normal file
View File

@@ -0,0 +1,14 @@
import ArgumentParser
@main
struct DuctCalcCli: AsyncParsableCommand {
static let configuration: CommandConfiguration = .init(
commandName: "ductcalc",
abstract: "Perform duct calculations.",
subcommands: [
ConvertCommand.self,
SizeCommand.self,
],
defaultSubcommand: SizeCommand.self
)
}

View File

@@ -0,0 +1,35 @@
import ArgumentParser
import Dependencies
import ManualDClient
struct ConvertCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "convert",
abstract: "Convert to an equivalent recangular size."
)
@Option(
name: .shortAndLong,
help: "The height"
)
var height: Int
@Argument(
// name: .shortAndLong,
help: "The round size."
)
var roundSize: Int
func run() async throws {
@Dependency(\.manualD) var manualD
let size = try await manualD.rectangularSize(
round: .init(roundSize),
height: .init(height)
)
print("\(size.width) x \(height)")
}
}

View File

@@ -0,0 +1,35 @@
import ArgumentParser
import Dependencies
import ManualDClient
struct SizeCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "size",
abstract: "Calculate the required size of a duct."
)
@Option(
name: .shortAndLong,
help: "The design friction rate."
)
var frictionRate: Double = 0.06
@Argument(
help: "The required CFM for the duct."
)
var cfm: Int
func run() async throws {
@Dependency(\.manualD) var manualD
let size = try await manualD.ductSize(cfm: cfm, frictionRate: frictionRate)
print(
"""
Calculated: \(size.calculatedSize.string(digits: 2))
Final Size: \(size.finalSize)
Flex Size: \(size.flexSize)
"""
)
}
}

View File

@@ -1,4 +1,3 @@
Name,Heating Load,Cooling Total,Cooling Sensible,Register Count,Delegated To Name,Heating Load,Cooling Total,Cooling Sensible,Register Count,Delegated To
Bed-1,12345,1234,1321,1, Bed-1,12345,1234,1321,1,
Entry,3456,2345,1234,1, Entry,3456,2345,1234,1,
1 Name Heating Load Cooling Total Cooling Sensible Register Count Delegated To
Name Heating Load Cooling Total Cooling Sensible Register Count Delegated To
1 Bed-1 Name 12345 Heating Load 1234 Cooling Total 1321 Cooling Sensible 1 Register Count Delegated To
2 Entry Bed-1 3456 12345 2345 1234 1234 1321 1
3 Kitchen Entry 7654 3456 3456 2345 2453 1234 2 1