Commandy is Cli framework.
non option
enum Stash: Command {
static func run() throws {
print("git stash")
}
}
option
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 |
enum Git: String, Commandy.Cli {
case commit
case stash
func run() throws {
switch self {
case .commit: try Commit.run()
case .stash: try Stash.run()
}
}
}
try YourCli().run()
❯ 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"]
.package(url: "https://github.com/atsushi130/Commandy", from: "1.0.0"),
Commandy is available under the MIT license. See the LICENSE file.