ParserError.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. /// Gets thrown while parsing and will be handled by the error output generation.
  12. enum ParserError: Error {
  13. case helpRequested(visibility: ArgumentVisibility)
  14. case versionRequested
  15. case dumpHelpRequested
  16. case completionScriptRequested(shell: String?)
  17. case completionScriptCustomResponse(String)
  18. case unsupportedShell(String? = nil)
  19. case notImplemented
  20. case invalidState
  21. case unknownOption(InputOrigin.Element, Name)
  22. case invalidOption(String)
  23. case nonAlphanumericShortOption(Character)
  24. /// The option was there, but its value is missing, e.g. `--name` but no value for the `name`.
  25. case missingValueForOption(InputOrigin, Name)
  26. case missingValueOrUnknownCompositeOption(InputOrigin, Name, Name)
  27. case unexpectedValueForOption(InputOrigin.Element, Name, String)
  28. case unexpectedExtraValues([(InputOrigin, String)])
  29. case duplicateExclusiveValues(
  30. previous: InputOrigin, duplicate: InputOrigin, originalInput: [String])
  31. /// We need a value for the given key, but it’s not there. Some non-optional option or argument is missing.
  32. case noValue(forKey: InputKey)
  33. case unableToParseValue(
  34. InputOrigin, Name?, String, forKey: InputKey, originalError: Error?)
  35. case missingSubcommand
  36. case userValidationError(Error)
  37. case noArguments(Error)
  38. case notParentCommand(String)
  39. }
  40. /// These are errors used internally to the parsing, and will not be exposed to the help generation.
  41. enum InternalParseError: Error {
  42. case wrongType(valueRepresentation: String, forKey: InputKey)
  43. case subcommandNameMismatch
  44. case subcommandLevelMismatch(Int, Int)
  45. case subcommandLevelMissing(Int)
  46. case subcommandLevelDuplicated(Int)
  47. case expectedCommandButNoneFound
  48. }