Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kylef/Commander
Compose beautiful command line interfaces in Swift
https://github.com/kylef/Commander
Last synced: about 1 month ago
JSON representation
Compose beautiful command line interfaces in Swift
- Host: GitHub
- URL: https://github.com/kylef/Commander
- Owner: kylef
- License: bsd-3-clause
- Created: 2014-07-05T13:15:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T09:37:37.000Z (almost 3 years ago)
- Last Synced: 2024-12-06T14:03:52.884Z (about 1 month ago)
- Language: Swift
- Homepage:
- Size: 225 KB
- Stars: 1,529
- Watchers: 18
- Forks: 86
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Commander - Compose beautiful command line interfaces in Swift. (Command Line / Linter)
- awesome-swift - Commander - Compose beautiful command line interfaces. (Libs / Command Line)
- awesome-swift - Commander - Compose beautiful command line interfaces. (Libs / Command Line)
- awesome-cli-frameworks - Commander
- fucking-awesome-swift - Commander - Compose beautiful command line interfaces. (Libs / Command Line)
- awesome-ios-star - Commander - Compose beautiful command line interfaces in Swift. (Command Line / Linter)
- awesome-system-swift - Commander - line **arguments**. (The Index / Command Line UI tools)
- awesome-swift-cn - Commander - Compose beautiful command line interfaces in Swift. (Libs / Command Line)
- fucking-awesome-ios - Commander - Compose beautiful command line interfaces in Swift. (Command Line / Linter)
- fucking-awesome-ios - Commander - Compose beautiful command line interfaces in Swift. (Command Line / Linter)
- awesome-swift - Commander - Compose beautiful command line interfaces in Swift ` 📝 18 days ago ` (Command Line [🔝](#readme))
README
# Commander
[![Build Status](https://img.shields.io/travis/kylef/Commander/master.svg?style=flat)](https://travis-ci.org/kylef/Commander)
Commander is a small Swift framework allowing you to craft beautiful command
line interfaces in a composable way.## Usage
##### Simple Hello World
```swift
import Commanderlet main = command { (filename:String) in
print("Reading file \(filename)...")
}main.run()
```##### Type-safe argument handling
The closure passed to the command function takes any arguments that
conform to `ArgumentConvertible`, Commander will automatically convert the
arguments to these types. If they can't be converted the user will receive a
nice error message informing them that their argument doesn't match the
expected type.`String`, `Int`, `Double`, and `Float` are extended to conform to
`ArgumentConvertible`, you can easily extend any other class or structure
so you can use it as an argument to your command.```swift
command { (hostname:String, port:Int) in
print("Connecting to \(hostname) on port \(port)...")
}
```##### Grouping commands
You can group a collection of commands together.
```swift
Group {
$0.command("login") { (name:String) in
print("Hello \(name)")
}$0.command("logout") {
print("Goodbye.")
}
}
```Usage:
```shell
$ auth
Usage:$ auth COMMAND
Commands:
+ login
+ logout$ auth login Kyle
Hello Kyle
$ auth logout
Goodbye.
```#### Describing arguments
You can describe positional arguments and options for a command to auto-generate help.
This is done by passing in descriptors of these arguments.For example, for fixed positional arguments with descriptions, you can use:
```swift
command(
Argument("name", description: "Your name"),
Argument("surname", description: "Your surname"),
Argument("count", description: "Number of times to print")
) { name, surname, count in
for _ in 0..