feat: Adds minimal cli executable and commands.
All checks were successful
CI / Linux Tests (push) Successful in 6m44s
All checks were successful
CI / Linux Tests (push) Successful in 6m44s
This commit is contained in:
14
Sources/CLI/Cli.swift
Normal file
14
Sources/CLI/Cli.swift
Normal 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
|
||||
)
|
||||
}
|
||||
35
Sources/CLI/Commands/Convert.swift
Normal file
35
Sources/CLI/Commands/Convert.swift
Normal 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)")
|
||||
}
|
||||
|
||||
}
|
||||
35
Sources/CLI/Commands/Size.swift
Normal file
35
Sources/CLI/Commands/Size.swift
Normal 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)
|
||||
"""
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user