Files
Rauhul Varma 10d80282e5 Enable swift-format checking (#711)
Adopts the common swift-mmio and swift-argument-parser format and enables CI checking.

Fixes: #702
2025-02-10 14:58:19 -08:00

59 lines
1.4 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import ArgumentParser
@main
struct Color: ParsableCommand {
@Option(help: "Your favorite color.")
var fav: ColorOptions
@Option(
help: .init("Your second favorite color.", discussion: "This is optional."))
var second: ColorOptions?
func run() {
print("My favorite color is \(fav.rawValue)")
if let second {
print("...And my second favorite is \(second.rawValue)!")
}
}
}
public enum ColorOptions: String, CaseIterable, ExpressibleByArgument {
case red
case blue
case yellow
public var defaultValueDescription: String {
switch self {
case .red:
return "A red color."
case .blue:
return "A blue color."
case .yellow:
return "A yellow color."
}
}
public var description: String {
switch self {
case .red:
return "A red color."
case .blue:
return "A blue color."
case .yellow:
return "A yellow color."
}
}
}