How do you access command line arguments for a command line application in Swift?
Apple has released the ArgumentParser library for doing just this:
We’re delighted to announce
ArgumentParser, a new open-source library that makes it straightforward — even enjoyable! — to parse command-line arguments in Swift.https://swift.org/blog/argument-parser/
https://github.com/apple/swift-argument-parser
Begin by declaring a type that defines the information you need to collect from the command line. Decorate each stored property with one of
ArgumentParser's property wrappers, and declare conformance toParsableCommand.The
ArgumentParserlibrary parses the command-line arguments, instantiates your command type, and then either executes your customrun()method or exits with useful a message.