ArgumentHelp.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // This source file is part of the Swift Argument Parser open source project
  4. //
  5. // Copyright (c) 2020 Apple Inc. and the Swift project authors
  6. // Licensed under Apache License v2.0 with Runtime Library Exception
  7. //
  8. // See https://swift.org/LICENSE.txt for license information
  9. //
  10. //===----------------------------------------------------------------------===//
  11. /// Help information for a command-line argument.
  12. public struct ArgumentHelp {
  13. /// A short description of the argument.
  14. public var abstract: String = ""
  15. /// An expanded description of the argument, in plain text form.
  16. public var discussion: String?
  17. /// An alternative name to use for the argument's value when showing usage
  18. /// information.
  19. ///
  20. /// - Note: This property is ignored when generating help for flags, since
  21. /// flags don't include a value.
  22. public var valueName: String?
  23. /// A visibility level indicating whether this argument should be shown in
  24. /// the extended help display.
  25. public var visibility: ArgumentVisibility = .default
  26. /// A Boolean value indicating whether this argument should be shown in
  27. /// the extended help display.
  28. @available(*, deprecated, message: "Use visibility level instead.")
  29. public var shouldDisplay: Bool {
  30. get {
  31. visibility.base == .default
  32. }
  33. set {
  34. visibility = newValue ? .default : .hidden
  35. }
  36. }
  37. /// A property of meta type `any ExpressibleByArgument.Type` that serves to retain
  38. /// information about any arguments that have enumerable values and their descriptions.
  39. public var argumentType: (any ExpressibleByArgument.Type)?
  40. /// Creates a new help instance.
  41. @available(
  42. *, deprecated,
  43. message: "Use init(_:discussion:valueName:visibility:) instead."
  44. )
  45. public init(
  46. _ abstract: String = "",
  47. discussion: String? = nil,
  48. valueName: String? = nil,
  49. shouldDisplay: Bool
  50. ) {
  51. self.abstract = abstract
  52. self.discussion = discussion
  53. self.valueName = valueName
  54. self.shouldDisplay = shouldDisplay
  55. }
  56. /// Creates a new help instance.
  57. public init(
  58. _ abstract: String = "",
  59. discussion: String? = nil,
  60. valueName: String? = nil,
  61. visibility: ArgumentVisibility = .default,
  62. argumentType: (any ExpressibleByArgument.Type)? = nil
  63. ) {
  64. self.abstract = abstract
  65. self.discussion = discussion
  66. self.valueName = valueName
  67. self.visibility = visibility
  68. self.argumentType = argumentType
  69. }
  70. /// A `Help` instance that shows an argument only in the extended help display.
  71. public static var hidden: ArgumentHelp {
  72. ArgumentHelp(visibility: .hidden)
  73. }
  74. /// A `Help` instance that hides an argument from the extended help display.
  75. public static var `private`: ArgumentHelp {
  76. ArgumentHelp(visibility: .private)
  77. }
  78. }
  79. extension ArgumentHelp: Sendable {}
  80. extension ArgumentHelp: ExpressibleByStringInterpolation {
  81. public init(stringLiteral value: String) {
  82. self.abstract = value
  83. }
  84. }