https://github.com/atsushi130/commandy
Commandy is Cli framework for Swift.
https://github.com/atsushi130/commandy
cli command-line-tool commandy serverside-swift swift-cli
Last synced: 4 months ago
JSON representation
Commandy is Cli framework for Swift.
- Host: GitHub
- URL: https://github.com/atsushi130/commandy
- Owner: atsushi130
- License: mit
- Created: 2018-07-28T06:48:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-05T03:01:44.000Z (about 6 years ago)
- Last Synced: 2025-01-19T22:40:03.814Z (5 months ago)
- Topics: cli, command-line-tool, commandy, serverside-swift, swift-cli
- Language: Swift
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license-mit
Awesome Lists containing this project
README
Commandy
Commandy is Cli framework.
## Usage
### Implement Command
**non option**
```swift
enum Stash: Command {
static func run() throws {
print("git stash")
}
}
```**option**
```swift
enum Commit: String, Command {case message
case allowEmpty
var shortOption: String? {
switch self {
case .message: return "m"
default: return nil
}
}static func run() throws {
let matchOptions = Commit.matchOptions
switch matchOptions {
case _ where matchOptions[.message]:
print("git commit -m")
case _ where matchOptions[.allowEmpty, .message]:
print("git commit --allow-empty -m")
default: break
}
}
}
```Analysis method of command options is as follows:
|definition|prefix|separator|example word|analyzed|
|---|---|---|---|---|
|single-word|`--`||message|--message|
|multiple-word|`--`|`-`|allowEmpty|--allow-empty|### Implement Cli
```swift
enum Git: String, Commandy.Cli {case commit
case stashfunc run() throws {
switch self {
case .commit: try Commit.run()
case .stash: try Stash.run()
}
}
}
```### Running
```swift
try YourCli().run()
```### Arguments
```swift
❯ git commit
let command = Arguments.cached.command // Optional("commit")❯ git commit -m hello_world
let nonOptionArguments = Arguments.cached.nonOptionArguments.first // Optional("hello_world")❯ git commit --allow-empty -m hello_world
let options = Arguments.cached.options // ["--allow-empty", "-m"]
```## Installation via Swift Package Manager
```swift
.package(url: "https://github.com/atsushi130/Commandy", from: "1.0.0"),
```## License
Commandy is available under the MIT license. See the [LICENSE file](https://github.com/atsushi130/Commandy/blob/master/license-mit).