AECli
Swift package for making simple command line tools
I made this for personal use, but feel free to use it or contribute.
Intro
There is a Command
which can run some arguments in Cli
which has its Output
and contains any defined commands. For the example of a more custom implementation,
see AETool.
Example
Create executable Swift package and open it with Xcode
mkdir My && cd My && swift package init --type executable && xed .
Edit Package.swift
// swift-tools-version:5.1
import PackageDescription
let package = Package(
name: "My",
products: [
.executable(name: "my", targets: ["My"])
],
dependencies: [
.package(url: "https://github.com/tadija/AECli.git", from: "0.1.0")
],
targets: [
.target(name: "My", dependencies: ["AECli"]),
]
)
Edit Sources/My/main.swift
import AECli
// MARK: - Commands
struct Thing: Command {
var overview: String {
"does something"
}
var commands: [Command] {
[Foo(), Bar()]
}
}
struct Foo: Command {
var overview: String {
"foo something"
}
func run(_ arguments: [String] = [], in cli: Cli) throws {
cli.output("foo")
}
}
struct Bar: Command {
var overview: String {
"bar something"
}
func run(_ arguments: [String] = [], in cli: Cli) throws {
cli.output("bar")
}
}
// MARK: - Cli
SimpleCli(
overview: "my cli",
commands: [Thing()],
help: "USAGE: command [options]"
).launch()
Install
swift build -c release && install .build/release/my /usr/local/bin/my
Uninstall
rm /usr/local/bin/my
Usage
Installation
License
This code is released under the MIT license. See LICENSE for details.
AECli
Swift package for making simple command line tools
Intro
There is a
Command
which can run some arguments inCli
which has itsOutput
and contains any defined commands. For the example of a more custom implementation, see AETool.Example
Create executable Swift package and open it with Xcode
Edit
Package.swift
Edit
Sources/My/main.swift
Install
Uninstall
Usage
Run my
Run thing command
Run foo command
Installation
Swift Package Manager:
License
This code is released under the MIT license. See LICENSE for details.