Swift Package Index

ArgParse

https://github.com/kyouko-taiga/argparse.git

Pure Swift utility for command-line options and arguments.


Compatibility

  • 1.1.0 and master
    5.3
    5.2
    5.1
    5.0
    4.2
  • 1.1.0 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS

ArgParse

Build Status

Pure Swift utility for command-line options and arguments, inspired by Python's argpase module.

Usage example

The following code is a Swift program that takes a list of integers and filters out the even numbers unless asked otherwise.

import ArgParse

let parser: ArgumentParser = [
  .variadic("elements", defaultValue: [Int]()),
  .flag("keep-even", alias: "-e"),
]

if let parseResult = try? parser.parse(CommandLine.arguments) {
  let elements: [Int] = parseResult.result(for: "elements")!
  let keepEven: Bool = parseResult.result(for: "keep-even")!
  print(elements.filter { $0 % 2 != 0 || keepEven })
}