ArgParse

1.1.0

Pure Swift utility for command-line options and arguments.
kyouko-taiga/ArgParse

What's New

Version 1.1.0

2018-10-23T08:24:51Z

Add a help manual generator

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 })
}

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 08:01:50 GMT-0900 (Hawaii-Aleutian Daylight Time)