Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions Sources/ExFig/Subcommands/GenerateConfigFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ extension ExFigCommand {
var globalOptions: GlobalOptions

@Option(name: .shortAndLong, help: "Platform: ios or android.")
var platform: Platform
var platform: Platform?

func run() async throws {
ExFigCommand.initializeTerminalUI(verbose: globalOptions.verbose, quiet: globalOptions.quiet)
let ui = ExFigCommand.terminalUI!

let fileContents: String = switch platform {
let selectedPlatform: Platform
if let p = platform {
selectedPlatform = p
} else {
if !TTYDetector.isTTY {
throw ValidationError("Missing expected argument '--platform <platform>'")
}
selectedPlatform = try promptForPlatform(ui: ui)
}

let fileContents: String = switch selectedPlatform {
case .android:
androidConfigFileContents
case .ios:
Expand Down Expand Up @@ -119,5 +129,30 @@ extension ExFigCommand {
throw ExFigError.custom(errorString: "Unable to create config file at: \(destination)")
}
}

private func promptForPlatform(ui: TerminalUI) throws -> Platform {
ui.info("Select a platform:")
let platforms = Platform.allCases
for (index, platform) in platforms.enumerated() {
ui.info("\(index + 1). \(platform.rawValue)")
}

while true {
TerminalOutputManager.shared.writeDirect("Enter selection [1-\(platforms.count)]: ")
ANSICodes.flushStdout()

guard let input = readLine() else {
TerminalOutputManager.shared.writeDirect("\n")
throw ExFigError.custom(errorString: "Operation cancelled.")
}

if let index = Int(input.trimmingCharacters(in: .whitespacesAndNewlines)),
index > 0, index <= platforms.count
{
return platforms[index - 1]
}
ui.error("Invalid selection. Please try again.")
}
}
}
}
2 changes: 1 addition & 1 deletion Sources/ExFigCore/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
///
/// ExFig supports exporting to both iOS (Xcode) and Android (Android Studio) projects.
/// The platform affects naming conventions, output formats, and generated code.
public enum Platform: String, Sendable {
public enum Platform: String, CaseIterable, Sendable {
/// iOS/iPadOS/macOS platform (Xcode projects).
/// Generates xcassets, Swift extensions for UIKit and SwiftUI.
case ios
Expand Down
4 changes: 4 additions & 0 deletions mise.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ git-cliff = "2.10.1" # Changelog generation

# --- Configuration ---
pkl = "0.30.2" # Configuration language (for hk.pkl)
swift = "6.2.3"

# =============================================================================
# Tasks
Expand Down
Loading