CodeGeneratorParameter.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Sources/SwiftProtobufPluginLibrary/CodeGeneratorParameter.swift
  2. //
  3. // Copyright (c) 2014 - 2023 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. // -----------------------------------------------------------------------------
  10. ///
  11. /// This provides the basic interface for a CodeGeneratorParameter. This is
  12. /// passed to the `CodeGenerator` to get any command line options.
  13. ///
  14. // -----------------------------------------------------------------------------
  15. import Foundation
  16. /// The the generator specific parameter that was passed to the protocol
  17. /// compiler invocation. The protocol buffer compiler supports providing
  18. /// parameters via the `--[LANG]_out` or `--[LANG]_opt` command line flags.
  19. /// The compiler will relay those through as a _parameter_ string.
  20. public protocol CodeGeneratorParameter {
  21. /// The raw value from the compiler as a single string, if multiple values
  22. /// were passed, they are joined into a single string. See `parsedPairs` as
  23. /// that is likely a better option for consuming the parameters.
  24. var parameter: String { get }
  25. /// The protocol buffer compiler will combine multiple `--[LANG]_opt`
  26. /// directives into a "single" parameter by joining them with commas. This
  27. /// vends the parameter split back back out into the individual arguments:
  28. /// i.e.,
  29. /// "foo=bar,baz,mumble=blah"
  30. /// becomes:
  31. /// [
  32. /// (key: "foo", value: "bar"),
  33. /// (key: "baz", value: ""),
  34. /// (key: "mumble", value: "blah")
  35. /// ]
  36. var parsedPairs: [(key: String, value: String)] { get }
  37. }