Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: state respectful SakeAppManager #29

Merged
merged 14 commits into from
Jan 13, 2025
4 changes: 2 additions & 2 deletions Sources/SakeCLI/BuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ struct BuildCommand: ParsableCommand {
let configManager = ConfigManager(cliConfig: CLIConfig(commonOptions: options, commandRelatedOptions: nil))
let config = try configManager.resolvedConfig()

let manager = SakeAppManager.default(sakeAppPath: config.sakeAppPath)
let manager: SakeAppManager<InitializedMode> = try .makeInInitializedMode(sakeAppPath: config.sakeAppPath)
if showBinPath {
let binPath = try manager.getExecutablePath()
print(binPath)
} else {
try manager.buildSakeAppExecutable()
try manager.buildExecutable()
}
} catch {
logError(error.localizedDescription)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SakeCLI/CleanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct CleanCommand: ParsableCommand {
let configManager = ConfigManager(cliConfig: CLIConfig(commonOptions: options, commandRelatedOptions: nil))
let config = try configManager.resolvedConfig()

let manager = SakeAppManager.default(sakeAppPath: config.sakeAppPath)
let manager: SakeAppManager<InitializedMode> = try .makeInInitializedMode(sakeAppPath: config.sakeAppPath)
try manager.clean()
} catch {
logError(error.localizedDescription)
Expand Down
5 changes: 3 additions & 2 deletions Sources/SakeCLI/InitCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ struct InitCommand: ParsableCommand {
let configManager = ConfigManager(cliConfig: CLIConfig(commonOptions: options, commandRelatedOptions: nil))
let config = try configManager.resolvedConfig()

let manager = SakeAppManager.default(sakeAppPath: config.sakeAppPath)
try manager.initialize()
let uninitializedModeManager: SakeAppManager<UninitializedMode> = .makeInUninitializedMode(sakeAppPath: config.sakeAppPath)
let initializedModeManager = try uninitializedModeManager.initializeProject()
try initializedModeManager.buildExecutable()
} catch {
logError(error.localizedDescription)
InitCommand.exit(withError: ExitCode.failure)
Expand Down
6 changes: 3 additions & 3 deletions Sources/SakeCLI/ListCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ struct ListCommand: ParsableCommand {
let configManager = ConfigManager(cliConfig: CLIConfig(commonOptions: options, commandRelatedOptions: commandRelatedOptions))
let config = try configManager.resolvedConfig()

let manager = SakeAppManager.default(sakeAppPath: config.sakeAppPath)
let manager: SakeAppManager<InitializedMode> = try .makeInInitializedMode(sakeAppPath: config.sakeAppPath)
try manager.listAvailableCommands(
prebuiltExecutablePath: config.sakeAppPrebuiltBinaryPath,
caseConvertingStrategy: config.caseConvertingStrategy,
json: json
)
} catch {
if case let SakeAppManager.Error.sakeAppError(sakeAppError) = error {
if case let SakeAppManagerError.sakeAppError(sakeAppError) = error {
// log only unexpected errors, business errors are already pretty logged by the SakeApp
if case SakeAppManager.SakeAppError.unexpectedError = sakeAppError {
if case SakeAppManagerError.SakeAppError.unexpectedError = sakeAppError {
logError(error.localizedDescription)
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/SakeCLI/RunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ struct RunCommand: ParsableCommand {
let configManager = ConfigManager(cliConfig: CLIConfig(commonOptions: options, commandRelatedOptions: commandRelatedOptions))
let config = try configManager.resolvedConfig()

let manager = SakeAppManager.default(sakeAppPath: config.sakeAppPath)
let manager: SakeAppManager<InitializedMode> = try .makeInInitializedMode(sakeAppPath: config.sakeAppPath)
try manager.run(
prebuiltExecutablePath: config.sakeAppPrebuiltBinaryPath,
command: command,
args: args,
caseConvertingStrategy: config.caseConvertingStrategy
)
} catch {
if case let SakeAppManager.Error.sakeAppError(sakeAppError) = error {
if case let SakeAppManagerError.sakeAppError(sakeAppError) = error {
// log only unexpected errors, business errors are already pretty logged by the SakeApp
if case SakeAppManager.SakeAppError.unexpectedError = sakeAppError {
if case SakeAppManagerError.SakeAppError.unexpectedError = sakeAppError {
logError(error.localizedDescription)
}
} else {
Expand Down
121 changes: 0 additions & 121 deletions Sources/SakeCLI/SakeAppManager/SakeAppManager+CommandExecutor.swift

This file was deleted.

121 changes: 0 additions & 121 deletions Sources/SakeCLI/SakeAppManager/SakeAppManager+FileHandle.swift

This file was deleted.

Loading
Loading