Shell scripting in Swift

Related tags

Command Line Shwift
Overview

Shwift

Shell-scripting in Swift

DISCLAIMER: Shwift depends on Swift's incoming concurrency features. As such, it requires a recent Swift toolchain, and changes in the toolchain may break provided functionality without notice. This project was last seen working with the 2021-05-04 toolchain in Xcode.

Overview

Shwift aims to provide a full-featured framework for creating shell-script-like tools using Swift. We are particularly excited about the prospect of building scripts using swift-argument-parser.

Shwift is built around two salient design points. Firstly, we want running a shell command to behave as similarly as possible to invoking a regular Swift function. For instance, we should be able to set a breakpoint on a line containing try await echo("Foo") | sed("s/Foo/Bar/"), and stepping over this line should log Bar to the standard out. Second we want piping between executables and native Swift code to be as low-friction as possible . Indeed, in the earlier example echo is a builtin implemented in Swift. We also aim to offer more sophisticated builtins for interfacing with shell scripts. The first of these is process which allows the user to process as much input as they need and return a Swift value.

We recommend looking at Sample.swift for a few examples of how this can be used.

Comments
  • NIO provides basic async/await API already

    NIO provides basic async/await API already

    https://github.com/GeorgeLyon/Shwift/blob/8fb57012a1555cdd62243ac6504018f9b6fcddd5/Sources/Shwift/NIO.swift#L5

    They are :). If you import _NIOConcurrency, then you should be able to just use try await channel.close(). EventLoopFuture also has func get() async throws, and EventLoopPromise can be fulfilled with an async computation.

    --> https://github.com/apple/swift-nio/blob/main/Sources/_NIOConcurrency/AsyncAwaitSupport.swift

    opened by weissi 1
  • Dust off documentation and clean up some API

    Dust off documentation and clean up some API

    This commit adds a bunch of documentation to various parts of Shwift.

    It also tweaks a few APIs, most notably removing the API for reading values from Environment. This is because Environment is only designed to pass an environment to a command-line tool, and not as a dictionary of environment variables (for instance, it uses a linear scan to get values from the environment when it needs to).

    opened by GeorgeLyon 0
  • Add `Process.launch` which returns after exec

    Add `Process.launch` which returns after exec

    Process.launch returns a Task which represents the running executable. This task can be cancelled and awaited like any other Swift Task. Cancellation sends SIGTERM to the child.

    opened by GeorgeLyon 0
  • Come up with better API for abstracting file descriptors

    Come up with better API for abstracting file descriptors

    Currently, projects which use Shwift end up with some awkwardly nested structures when using Output and Input as file descriptors. This feels especially bloated when dealing with "null" inputs like nullDevice. We can probably do better.

    opened by GeorgeLyon 0
  • Command hangs when piped to a builtin which does not read from the input

    Command hangs when piped to a builtin which does not read from the input

    Uncommenting the following test demonstrates the issue: https://github.com/GeorgeLyon/Shwift/blob/8c9e74c1b091e019b85805fc84706760fce54fcc/Tests/ShellTests/Shell%20Tests.swift#L108-L114

    opened by GeorgeLyon 0
Releases(2.0.0)
  • 2.0.0(Oct 3, 2022)

    This 2.0 release does not profoundly change the API of Shwift or Script. It does remove a (likely unused) public API to read a value from an Environment.

    As an added bonus, Shwift is cleaned up for Swift 5.7 and much of the documentation has been improved.

    Source code(tar.gz)
    Source code(zip)
  • 1.2.1(Jan 11, 2022)

    What's Changed

    • Add public init for Recorder by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/12

    Full Changelog: https://github.com/GeorgeLyon/Shwift/compare/1.2.0...1.2.1

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Jan 11, 2022)

    What's Changed

    • Add Recorable Output by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/11

    Full Changelog: https://github.com/GeorgeLyon/Shwift/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Dec 29, 2021)

    What's Changed

    • Prefer CancellationError to uncaught SIGTERM by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/8
    • Add Process.launch which returns after exec by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/9

    Full Changelog: https://github.com/GeorgeLyon/Shwift/compare/1.0.2...1.0.3

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Dec 10, 2021)

    What's Changed

    • Add pipe variant where destination is PipableCommand by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/7
    • Also format tests by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/6

    Full Changelog: https://github.com/GeorgeLyon/Shwift/compare/1.0.1...1.0.2

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Dec 10, 2021)

    What's Changed

    • Fix throwing on nonzero exit status by @GeorgeLyon in https://github.com/GeorgeLyon/Shwift/pull/5

    Full Changelog: https://github.com/GeorgeLyon/Shwift/compare/1.0.0...1.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
George Lyon
George Lyon
đź“‹A hand-curated collection of useful and informative Swift Scripting materials.

Articles • Videos Articles Creating iOS Application Icons with SwiftUI by Eneko Alonso An interesting way to use SwiftUI with CLI for icon generation.

Artem Novichkov 196 Jan 7, 2023
Util for executing shell commands, and getting the results easily(data, string, and any decodable).

ShellExecutor Util for executing shell commands, and getting the results easily(data, string, and any decodable). Requirements Xcode 14.0+ Swift 5.7+

Yozone Wang 2 Jul 30, 2022
Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement.

Linenoise-Swift A pure Swift implementation of the Linenoise library. A minimal, zero-config readline replacement. Supports Mac OS and Linux Line edit

Andy Best 114 Dec 14, 2022
Swift tool to generate Module Interfaces for Swift projects.

ModuleInterface Swift tool to generate Module Interfaces for Swift projects. What is a Module Interface A Module Interface is what we commonly get usi

Jorge Revuelta 75 Dec 21, 2022
Swift-cli - Example of building command-line tools in Swift

swift-cli Example of building command-line tools in Swift Step 1: Create CLI wit

Noah Gift 2 Jan 17, 2022
Compose beautiful command line interfaces in Swift

Commander is a small Swift framework allowing you to craft beautiful command line interfaces in a composable way. Usage Simple Hello World i

Kyle Fuller 1.5k Dec 29, 2022
CommandLineKit - A pure Swift library for creating command-line interfaces

CommandLineKit A pure Swift library for creating command-line interfaces. Note: This project is no longer maintained. It's preserved here for historic

Ben Gollmer 1.1k Dec 1, 2022
Guaka - Smart and beautiful POSIX compliant CLI framework for Swift.

Guaka - Smart and beautiful POSIX compliant CLI framework for Swift. It helps you create modern and familiar CLI apps in the vein of widely used proje

Omar Abdelhafith 1.1k Dec 24, 2022
Progress.swift ⌛ Add beautiful progress bars to your loops.

Progress.swift ⌛ Just wrap the SequenceType in your loop with the Progress SequenceType and you'll automatically get beautiful progress bars. Updating

Justus Kandzi 304 Dec 1, 2022
Straightforward, type-safe argument parsing for Swift

Swift Argument Parser Usage Begin by declaring a type that defines the information that you need to collect from the command line. Decorate each store

Apple 2.9k Jan 7, 2023
SwiftCLI - A powerful framework for developing CLIs in Swift

SwiftCLI A powerful framework for developing CLIs, from the simplest to the most complex, in Swift.

Jake Heiser 793 Jan 4, 2023
SwiftyTextTable - A lightweight Swift library for generating text tables

SwiftyTextTable A lightweight Swift library for generating text tables. Swift Language Support SwiftyTextTable is now Swift 4.0 compatible! The last r

Scott Hoyt 283 Dec 23, 2022
Swift utilities for running commands.

Swift Commands Swift utilities for running commands. The Commands module allows you to take a system command as a string and return the standard outpu

Phil 41 Jan 2, 2023
A CLI too powered by Swift to provision environments using an up.toml manifest file

tuist-up tuist up was originally a Tuist built-in command to provision environments by reading the requirements in a manifest file Setup.swift. Althou

Tuist 5 Mar 31, 2022
Terminal string styling for Swift.

Terminal string styling for Swift. Integration Swift Package Manager (SPM) You can use The Swift Package Manager to install ColorizeSwift by adding it

Michał Tynior 281 Dec 22, 2022
Simple & Elegant Command Line Interfaces in Swift

An elegant pure Swift library for building command line applications. Features Tons of class, but no classes. 100% organic pure value types. Auto gene

hypertalk 52 Nov 9, 2022
✏️Expressive styling on terminal string. (chalk for swift)

Chalk Expressive styling on terminal string. Highlights Expressive API 256/TrueColor support Nest styles Auto downgrading to terminal supported color

Luo Xiu 59 Jun 10, 2022
A starting point to create CLI utilities with swift

cli tuist template A starting point to create CLI utilities with swift Installation Just create a Tuist folder and a Templates folder inside it. Creat

humdrum 6 May 3, 2022
A Tuist Template to quickly create CLI apps in Swift

macOS CLI Template Motivation I'm writing more and more Swift CLI apps these days. And as I solve more problems with this litte tools, I find that I'm

Diego Freniche 21 Dec 28, 2022