Swiftpack.co - henrik-dmg/CLIFoundation as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by henrik-dmg.
henrik-dmg/CLIFoundation 0.8.0
A collection of helper methods and types to make creating CLI in Swift a breeze.
⭐️ 0
🕓 1 year ago
.package(url: "https://github.com/henrik-dmg/CLIFoundation.git", from: "0.8.0")

CLIFoundation

A collection of helper methods and types to make creating CLI in Swift a breeze.

Shell

With CLIFoundation you can easily launch bash commands in Swift. You can either run a command directly or construct a ShellCommand to get a safe command that will be formatted correctly automatically

Raw Command:

try Shell.execute("git -C some/repo/path commit -m \"Some commit message\" --no-verify")

Using Command:

// new, nice way
let command = Command("git") {
	Option("C", value: "some/repo/path")
	Argument("commit")
	Option("m", value: "\"Some commit message\"")
	Flag("no-verify")
}

// old way
let command = Command("git")
	.appendingOption("C", value: "some/repo/path")
	.appendingArgument("commit")
	.appendingOption("m", value: "\"Some commit message\"")
	.appendingFlag("no-verify")
try Shell.execute(command)

Text

CLIFoundation supports text styling with these methods:

return "This what we want to print to the terminal"
	.addingTerminalColor(.red)
	.addingTerminalBackgroundColor(.yellow)
	.addingTerminalTextDecoration(.bold)

or through a combined convenience method:

return "This what we want to print to the terminal"
	.addingTerminalStyling(color: .red, backgroundColor: .yellow, decoration: .bold)

Contribution

I don't have a contribution guide and all that fancy stuff so if you want to implement changes or add new stuff, feel free to do so and just assign me the PR. Happy coding! :-)

GitHub

link
Stars: 0
Last commit: 9 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

CommandBuilder API
2 years ago

With Swift 5.4, we finally got @resultBuilder so now there's a new CommandBuilder to make construction commands even easier. You can use it like this:

let command = Command("jazzy") {
    Argument("some-argument")
    Option("theme", value: "full-width")
    if someCondition {
        Flag("verbose")
    }
}

As you might have noticed though, ShellCommand has been renamed to Command

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics