1
1
mirror of https://github.com/nsomar/Swiftline.git synced 2024-07-14 17:00:35 +03:00

Adding SPM example

This commit is contained in:
Omar Abdelhafith 2016-02-14 18:05:13 +00:00
parent 321ab14390
commit c19a88ad06
5 changed files with 67 additions and 28 deletions

2
.gitignore vendored
View File

@ -170,3 +170,5 @@ crashlytics.properties
crashlytics-build.properties
Examples/Rome/
TestPackage/.build
.build/

View File

@ -23,3 +23,11 @@ build_help:
test:
cd SwiftlineTests; xctool -project Swiftline.xcodeproj -scheme Swiftline clean build test -sdk macosx GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES
test-spm:
cd TestPackage && rm -rf .build
cd TestPackage && swift build
build-spm:
rm -rf .build
swift build

View File

@ -2,30 +2,30 @@
<img src="http://swiftline.github.io/img/intro-bg.svg" width="400" align="middle"/>
<br/>
</p>
[![Build Status](https://travis-ci.org/Swiftline/Swiftline.svg?branch=master)](https://travis-ci.org/Swiftline/Swiftline)
[![Platform](https://img.shields.io/badge/platform-osx-lightgrey.svg)](https://travis-ci.org/Swiftline/Swiftline)
[![Language: Swift](https://img.shields.io/badge/language-swift-orange.svg)](https://travis-ci.org/Swiftline/Swiftline)
[![CocoaPods](https://img.shields.io/cocoapods/v/Swiftline.svg)](https://cocoapods.org/pods/Swiftline)
[![Carthage](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![GITTER: join chat](https://img.shields.io/badge/GITTER-join%20chat-00D06F.svg)](https://gitter.im/Swiftline?utm_source=share-link&utm_medium=link&utm_campaign=share-link)
[![GITTER: join chat](https://img.shields.io/badge/license-MIT-000000.svg)](https://github.com/Swiftline/Swiftline/blob/oarrabi/adding-env-and-args/LICENCE)
<br/>
Swiftline is a set of tools to help you create command line applications. Swiftline is inspired by [highline](https://github.com/JEG2/highline)
[![Build Status](https://travis-ci.org/Swiftline/Swiftline.svg?branch=master)](https://travis-ci.org/Swiftline/Swiftline)
[![Platform](https://img.shields.io/badge/platform-osx-lightgrey.svg)](https://travis-ci.org/Swiftline/Swiftline)
[![Language: Swift](https://img.shields.io/badge/language-swift-orange.svg)](https://travis-ci.org/Swiftline/Swiftline)
[![CocoaPods](https://img.shields.io/cocoapods/v/Swiftline.svg)](https://cocoapods.org/pods/Swiftline)
[![Carthage](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![GITTER: join chat](https://img.shields.io/badge/GITTER-join%20chat-00D06F.svg)](https://gitter.im/Swiftline?utm_source=share-link&utm_medium=link&utm_campaign=share-link)
[![GITTER: join chat](https://img.shields.io/badge/license-MIT-000000.svg)](https://github.com/Swiftline/Swiftline/blob/oarrabi/adding-env-and-args/LICENCE)
<br/>
Swiftline is a set of tools to help you create command line applications. Swiftline is inspired by [highline](https://github.com/JEG2/highline)
<br/>
Swiftline contains the following:
- Colorize: Helps adding colors to strings written to the terminal
- Ask , Choose and agree: Easily create prompt for asking the user more info
- Run: A quick way to run an external command and read its standard output and standard error.
- Run: A quick way to run an external command and read its standard output and standard error.
- Env: Read and write environment variables [ruby-flavored](http://ruby-doc.org/core-2.2.0/ENV.html)
- Args: Parses command line arguments and return a hash of the passed flags
## Contents
[Usage](#usage)
[Installation](#installation)
[Examples](#examples)
[Docs](http://swiftline.github.io/docs/index.html)
[Tests](#tests)
[Usage](#usage)
[Installation](#installation)
[Examples](#examples)
[Docs](http://swiftline.github.io/docs/index.html)
[Tests](#tests)
## Usage
@ -75,7 +75,7 @@ Ask can be used to ask for value of Int, Double or Float types, to ask for an in
let age = ask("How old are you?", type: Int.self)
```
If the user prints something thats not convertible to integer, a new prompt is displayed to him, this prompt will keep displaying until the user enters an Int:
How old are you?
None
You must enter a valid Integer.
@ -138,7 +138,7 @@ This will print:
Whats your favorite programming language?
The user can either choose the numbers (1..5) or the item itself. If the user enters a wrong input. A prompt will keep showing until the user makes a correct choice
Whats your favorite programming language? JavaScript
You must choose one of [1, 2, 3, 4, 5, Swift, Objective C, Ruby, Python, Java :S].
? BBB
@ -161,11 +161,11 @@ The number on the left can be changed to letters, here is how you could do that:
```siwft
let choice = choose("Whats your favorite programming language? ", type: String.self) { settings in
//choice value will be set to GOOD
settings.addChoice("Swift") { "GOOD" }
settings.addChoice("Swift") { "GOOD" }
//choice value will be set to BAD
settings.addChoice("Java") { "BAD" }
settings.index = .Letters
settings.indexSuffix = " ----> "
}
@ -191,7 +191,7 @@ If the user enters any invalid input, agree will keep prompting him for a Yes/No
Are you sure you want to `rm -rf /` ? Wait
Please enter "yes" or "no".
Are you sure you want to `rm -rf /` ? No
You entered false
## Run 🏃
@ -232,9 +232,9 @@ To customize the run function, you can pass in a customization block:
- `EchoSettings.Stdout`: The stdout returned from running the command will be printed to the terminal
- `EchoSettings.Stderr`: The stderr returned from running the command will be printed to the terminal
- `EchoSettings.Command`: The command executed will be printed to the terminal
- `settings.interactive`: defaults to false. If set to true the command will be executed using `system` kernel function and only the exit status will be captured. If set to false, the command will be executed using `NSTask` and both stdout and stderr will be captured.
Set `interactive` to true if you expect the launched command to ask input from the user through the stdin.
- `settings.interactive`: defaults to false. If set to true the command will be executed using `system` kernel function and only the exit status will be captured. If set to false, the command will be executed using `NSTask` and both stdout and stderr will be captured.
Set `interactive` to true if you expect the launched command to ask input from the user through the stdin.
`runWithoutCapture("command")` is a quick way to run a command in interactive mode. The return value is the exit code of that command.
## Env
@ -259,15 +259,15 @@ Returns the arguments passed to the script. For example when calling `script -f1
`Args.all ` returns an array of all the raw arguments, in this example it will be `["-f1", "val1", "-f2", "val2", "--", "val3", "val4"`
`Args.parsed ` returns a structure that contains a parsed map of arguments and an array of arguments, for this example:
`Args.parsed ` returns a structure that contains a parsed map of arguments and an array of arguments, for this example:
`Args.parsed.parameters` returns `["val3", "val4"]`
`Args.parsed.parameters` returns `["val3", "val4"]`
`Args.parsed.flags` returns a dictinary of flags `["f1": "val1", "f2", "val2"]`
## Installation
You can install Swiftline using cocoapods,
You can install Swiftline using cocoapods, carthage and Swift package manager
### Cocoapods
use_frameworks!
@ -276,6 +276,19 @@ You can install Swiftline using cocoapods,
### Carthage
github 'swiftline/swiftline'
### Swift Package Manager
Add swiftline as dependency in your `Package.swift`
```
import PackageDescription
let package = Package(name: "YourPackage",
dependencies: [
.Package(url: "https://github.com/Swiftline/Swiftline.git", majorVersion: 0, minor: 3),
]
)
```
### Cocoapods + Rome plugin
If you want to use swiftline in a script you can use [Rome](https://github.com/neonichu/Rome) cocoapod plugin. This plugin builds the framework from the pod file and place them in a Rome directory.
@ -284,7 +297,7 @@ If you want to use swiftline in a script you can use [Rome](https://github.com/n
pod 'Swiftline'
### Manual
### Manual
To install Swiftline manually, add `Pod/Swiftline` directory to your project.
## Examples
@ -304,5 +317,5 @@ Documentation can be found [here](http://swiftline.github.io/docs/index.html)
- Better documentation
## Credits
Daniel Beere for creating the logo [@DanielBeere](https://twitter.com/DanielBeere) check out [danielbeere on dribble](https://dribbble.com/danielbeere)
Daniel Beere for creating the logo [@DanielBeere](https://twitter.com/DanielBeere) check out [danielbeere on dribble](https://dribbble.com/danielbeere)
Omar Abdelhafith current project maintainer [@ifnottrue](https://twitter.com/ifnottrue)

View File

@ -0,0 +1,7 @@
import PackageDescription
let package = Package(name: "TestPackage",
dependencies: [
.Package(url: "../", majorVersion: 0, minor: 3),
]
)

View File

@ -0,0 +1,9 @@
import Swiftline
let res = ask("How are you doing?")
if res == "Good" {
print("Cool!")
} else {
print("Oh, bad!")
}