From 14e11dda03e022842135fd0ed5e7900d0c3e838b Mon Sep 17 00:00:00 2001 From: dianshi Date: Thu, 25 Mar 2021 07:42:42 +0000 Subject: input file parameter if not set then trow error --- OCRImage/main.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'OCRImage/main.swift') diff --git a/OCRImage/main.swift b/OCRImage/main.swift index 79d5b4b..cd3fafd 100644 --- a/OCRImage/main.swift +++ b/OCRImage/main.swift @@ -101,7 +101,7 @@ if #available(macOS 10.15,*) {} else { struct OCROptions : ParsableArguments { @Option(help:"Input file for OCR") - var inputFile:String = "/Projects/OCRImage/ExampleInput/sample.png" + var inputFile:String? @Flag(name: .shortAndLong, help:"Show extra debugion info") var debug=false @@ -118,15 +118,26 @@ if options.version { exit(0) } +//exit if input-file isnot set +//if nil == options.inputFile { +// print("Set --input-file command argument to image") +// exit(0) +//} +guard let inputFile = options.inputFile else { + print("ERROR: Set --input-file command argument to image") + exit(0) +} + + +print("OCR Input file: \(inputFile)") -print("OCR Input file: \(options.inputFile)") //Try to open file from URL var fm = FileManager.default.homeDirectoryForCurrentUser //let fm = FileManager.default print(fm) -let path:String = options.inputFile +let path:String = inputFile fm.appendPathComponent(path) let ocrImageUrl = fm.absoluteURL print(fm) -- cgit v1.2.3