https://github.com/dimpiax/commandlinerouter
Library for easy and flexible manipulation with `CommandLine.arguments` in executable product of Swift Package Manager
https://github.com/dimpiax/commandlinerouter
Last synced: 3 months ago
JSON representation
Library for easy and flexible manipulation with `CommandLine.arguments` in executable product of Swift Package Manager
- Host: GitHub
- URL: https://github.com/dimpiax/commandlinerouter
- Owner: dimpiax
- License: mit
- Created: 2016-11-06T00:53:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-10T01:48:24.000Z (over 8 years ago)
- Last Synced: 2025-01-08T18:41:35.272Z (5 months ago)
- Language: Swift
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CommandLineRouter
[](https://swift.org/blog/swift-3-0-released/)
[](https://github.com/dimpiax/CommandLineRouter/blob/master/LICENSE)
[](https://github.com/dimpiax/CommandLineRouter)## Description
Library for easy and flexible manipulation with `CommandLine.arguments` in executable product of Swift Package Manager## Usage
Run your executable product via SPM, and pass arguments
`$ .build/debug/Project -i input_file -o output_file`## Result
Output:
```
read file input_file
write file output_file
```# Example
```
import CommandLineRoutervar router = CommandLineRouter()
// setup routes
router.setCommands(name: "Save file", commands:
Command(shortName: "-i", name: "--input"),
Command(shortName: "-o", name: "--output")
)router.setCommands(name: "Export in folder", commands:
Command(shortName: "-i", name: "--input"),
Command(shortName: "-of", name: "--output-folder")
)// process routing
do {
try router.route(CommandLine.arguments) { flow in
switch flow.name {
case "Save file":
let input = flow[0].argument
let output = flow[1].argumentprint("read file \(argument)")
print("write file \(argument)")default: break
}
}
} catch {
print(error)
}
```