Skip to content

Instantly share code, notes, and snippets.

@DavidPiper94
Last active October 24, 2022 04:42
Show Gist options
  • Save DavidPiper94/84914202cab51adb1a3424ef861d6be4 to your computer and use it in GitHub Desktop.
Save DavidPiper94/84914202cab51adb1a3424ef861d6be4 to your computer and use it in GitHub Desktop.
Example code for article about ArgumentParser - Validation
// 1
func validate() throws {
let filePathWithExtension = "\(filePath)\(fileExtension)"
// 2
if FileManager.default.fileExists(atPath: filePathWithExtension) && force == false {
// 3
throw ValidationError("Given file already exists. To override it, please add `--force`.")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment