Phiole - Allow to write or read from standards stream or files for script or CLI application

Related tags

Command Line Phiole
Overview

No longer maintained!

Phiole - Φole

License Platform Language Issues Cocoapod

Simple object to wrap three NSFileHandle: 'output', 'error' to write and 'input' to read

There is of course a default instance for standard streams

let csl = Phiole.std

This object could be used in script or CLI application instead of using println(). This adds the following abilities :

  • Write to a file by declaring transparently an NSFileHandle as output stream
  • Write to error stream
  • Read from input stream

Swift scripts: How to write small command line scripts in Swift

⚠️ Phiole is not a login system. Use instead project like SLF4Swift

Usage

Write to ouput stream

csl.println("write string and pass to the new line")
csl.print("write string without new line")
csl.println() // write new line

Write to error stream

csl.errorln("write an error")

Read from user input

if line = csl.readLine() {
  // do something
}

Writing to a file

Create the file handle for writing (file must exist)

if let fileHandle = NSFileHandle(forWritingAtPath: "myoutput.file") { ..

Initialize the console object

var newCsl = csl.withOutput(fileHandle)
// or with more code
var newCsl = Phiole(input: input: Phiols.std.input,
                    output: fileHandle, error: Phiols.std.error)

Write as usual

newCsl.println("write to a file")
...

Finally don't forget to close the file handle at the end

fileHandle.closeFile()

Add some colors in terminal or xcode

You can manually add color with decorated method ( see PhioleColor.swift)

csl.println(Phiole.Color.green.fg("write in red"))

Or for all ouputs

csl.outputColor = .Green
csl.errorColor = .Red
... write here ...

// reset
csl.outputColor = .None
csl.errorColor = .None
// or deactivate
csl.colorize = false

Color shortcuts could be added as you can see in Phiole+Shortcut

For Xcode

XcodeColors is a simple plugin for Xcode, it allows you to use colors in the Xcode debugging console.

Full installation instructions can be found on the XcodeColors project page:
https://github.com/robbiehanson/XcodeColors

Then you must add environment variable XcodeColors = YES in your Scheme

More examples

In main.swift

Setup

Copy/Paste

Just copy/paste code with licence in your script, or import swift files or project in your CLI project

Using cocoapods

Add pod 'Phiole', :git => 'https://github.com/phimage/Phiole.git' to your Podfile and run pod install.

Add use_frameworks! to the end of the Podfile.

Licence

The MIT License (MIT)

Copyright (c) 2015 Eric Marchand (phimage)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Logo

By [kodlian] (http://www.kodlian.com/), inspired by apple swift logo

Why a logo?

I like to see an image for each of my projects when I browse them with SourceTree

You might also like...
ConcurrentTest - Swift macOS CLI example on how to NOT do concurrent coding
ConcurrentTest - Swift macOS CLI example on how to NOT do concurrent coding

Swift Concurrent Test Open the .xcodeproj file in Xcode, and try running it seve

A CLI utility to check or uncheck Open Using Rosetta preference for Apple Silicon macs.
A CLI utility to check or uncheck Open Using Rosetta preference for Apple Silicon macs.

SetArchPrefForURL A CLI utility to "check" or "uncheck" "Open Using Rosetta" preference for Apple Silicon macs. Usage: SetArchPrefForURL path-to-the-

A CLI to Alcatraz, the Xcode package manager.
A CLI to Alcatraz, the Xcode package manager.

Azkaban This project is deprecated in favor of Editor Extensions support in Xcode 8+. A CLI to Alcatraz, the Xcode package manager. Usage Install a pl

iOS command-line tool that allows searching and downloading ipa files from the iOS App Store

ipatool for iOS This is a port of Majd Alfhaily's ipatool adapted to run on iOS Build / Installation To build this, make sure you have AppSync install

Command-line utility that checks comments for localizations in iOS interface files (.xib, .storyboard)

Localizations Comments Checker It's really easy to overlook and don't add comment for localization in interface file (.storyboard or .xib). This comma

A command line application to create 3D models based on photogrametry using the macOS Monterey RealityCapture API.

PhotogrametryTool Generate 3D objects from images using RealityKit Object Capture. This project is a fork of the HelloPhotogrametry application by App

CodableCSV - Read and write CSV files row-by-row or through Swift's Codable interface.

CodableCSV provides: Imperative CSV reader/writer. Declarative CSV encoder/decoder. Support multiple inputs/outputs: Strings, Data blobs, URLs, and St

A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. 💡 Please note that this implementation of

A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. 💡 Please note that this implementation of

XcodeJSONValidator - XcodeJSONValidator is your script to to check for possible wrongly formed JSON files
XcodeJSONValidator - XcodeJSONValidator is your script to to check for possible wrongly formed JSON files

XcodeJSONValidator XcodeJSONValidator is your script to to check for possible wr

 📝 Read, update and write your Xcode projects
📝 Read, update and write your Xcode projects

XcodeProj XcodeProj is a library written in Swift for parsing and working with Xcode projects. It's heavily inspired by CocoaPods XcodeProj and xcode.

CSVParser - A swift library for fast read and write CSV file

CSVParser A swift library for fast read and write CSV file. This library supports all Apple platform and Linux. List to do get column by string subscr

Write amazing, strong-typed and easy-to-read NSPredicate.

PredicateFlow Write amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attrib

Write amazing, strong-typed and easy-to-read NSPredicate.

PredicateFlow Write amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attrib

Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.

ExtendaBLE Introduction ExtendaBLE provides a very flexible syntax for defining centrals and peripherals with ease. Following a blocks based builder a

Easy to read and write chainable animations in Objective-C and Swift
Easy to read and write chainable animations in Objective-C and Swift

Whats new in version 3.x? Swiftier syntax Swift 4 support Bug fixes and improvements Whats new in version 2.x? Re-architected from the ground up, no m

⛓ Easy to Read and Write Multi-chain Animations Lib in Objective-C and Swift.
⛓ Easy to Read and Write Multi-chain Animations Lib in Objective-C and Swift.

中文介绍 This project is inspired by JHChainableAnimations! Why Choose LSAnimator & CoreAnimator? You can write complex and easy-to-maintain animations in

ReadWriteLock - Swift Implementation of a standard Read/Write lock.

ReadWriteLock A Swift implementation of a Read/Write lock. I'm really amazed that the Swift Standard Library (nor the Objective-C standard library) ha

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Owner
Eric Marchand
🧙🍺🥊🥋🏓
Eric Marchand
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
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
CLI tool for macOS that transcribes speech from the microphone using Apple’s speech recognition API, SFSpeechRecognizer. (help.)

CLI tool for macOS that uses SFSpeechRecognizer to transcribe speech from the microphone. The recognition result will be written to the standard output as JSON string.

Thai Pangsakulyanont 23 Sep 20, 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
A cli program written in swift (with async/await) that removes the unnecessary parts of xcframeworks.

xctrim A cli program written in swift (with async/await) that removes the unnecessary parts of xcframeworks. Usecase Say you downloaded firebase sdk a

Mustafa Yusuf 32 Jul 18, 2022
An extremely simple CLI tool that was created to diagnose and further understand an issue in DriverKit causing kIOHIDOptionsTypeSeizeDevice to behave incorrectly when used in DriverKit system extensions.

IOKitHIDKeyboardTester This tool is NOT useful to, or intended for general users. IOKitHIDKeyboardTester is an extremely simple (one-file!) CLI tool t

Karen/あけみ 6 Jul 22, 2022
A library and CLI Utility to manage NVRAM Stuff, written in Swift.

NVRAMKit A Library and CLI Utility to manage NVRAM Stuff, written in Swift. Library Adding Library to Project Simply add this line to the dependencies

Serena 7 Sep 25, 2022
Snpm - Snippet Manager CLI With Swift

Snippet Manager CLI Usage foo@bar:~$ snpm --help OVERVIEW: Utill for searching s

Gleb Zavyalov 5 Jan 5, 2023
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