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
37 changes: 35 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 platform {
selectedPlatform = platform
} else {
if !TTYDetector.isTTY {
throw ValidationError("Missing required argument: --platform <ios|android|flutter|web>")
}
selectedPlatform = try promptForPlatform(ui: ui)
}

let fileContents: String = switch selectedPlatform {
case .android:
androidConfigFileContents
case .ios:
Expand Down Expand Up @@ -119,5 +129,28 @@ 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 to generate config for:")
let platforms = Platform.allCases
for (index, platform) in platforms.enumerated() {
ui.info("\(index + 1). \(platform.rawValue)")
}

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

guard let input = readLine(),
let index = Int(input.trimmingCharacters(in: .whitespacesAndNewlines)),
index > 0, index <= platforms.count
else {
ui.error("Invalid selection. Please enter a number between 1 and \(platforms.count).")
continue
}

return platforms[index - 1]
}
}
}
}
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, Sendable, CaseIterable {
/// iOS/iPadOS/macOS platform (Xcode projects).
/// Generates xcassets, Swift extensions for UIKit and SwiftUI.
case ios
Expand Down
Loading