Skip to content

Commit c40cedb

Browse files
committed
Add initial hello example
1 parent 5366537 commit c40cedb

File tree

5 files changed

+114
-5
lines changed

5 files changed

+114
-5
lines changed

Hello/Hello.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
// Hello
1+
public func hello(people: [String]) -> String {
2+
if people.isEmpty {
3+
return "Hello World"
4+
} else if people.count < 3 {
5+
return "Hello " + people.joinWithSeparator(" and ")
6+
}
7+
8+
let commaSeparatedPeople = people[0..<people.endIndex - 1].joinWithSeparator(", ")
9+
return "Hello \(commaSeparatedPeople) and \(people.last!)"
10+
}

HelloSpecs/HelloSpec.swift

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import Spectre
2+
import Hello
23

3-
describe("Hello") {
4-
$0.it("should be implemented") {
5-
throw failure("Not Implemented")
4+
describe("hello") {
5+
$0.it("should return 'Hello World' when no names were supplied") {
6+
try expect(hello([])) == "Hello World"
7+
}
8+
9+
$0.context("when given a single name") {
10+
$0.it("should return 'Hello' and the given name") {
11+
try expect(hello(["Kyle"])) == "Hello Kyle"
12+
}
13+
}
14+
15+
$0.context("when given two names") {
16+
$0.it("should return 'Hello' and the given names separated by 'and'") {
17+
try expect(hello(["Kyle", "Katie"])) == "Hello Kyle and Katie"
18+
}
19+
}
20+
21+
$0.context("when given three or more names") {
22+
$0.it("should return 'Hello' and the names separated by comma and 'and'") {
23+
try expect(hello(["Kyle", "Conche", "Katie"])) == "Hello Kyle, Conche and Katie"
24+
}
625
}
726
}

LICENSE

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2015, Kyle Fuller
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Conche CLI Example
2+
3+
This repository is a small example command line interface using the Conche
4+
build system. It was mostly generated via `conche init`.
5+
6+
```shell
7+
$ conche init Hello --with-cli --with-tests
8+
```
9+
10+
## Usage
11+
12+
This example provides a command called `hello` which can output Hello World
13+
or Hello and some given names.
14+
15+
```shell
16+
$ hello
17+
Hello World
18+
19+
$ hello Kyle
20+
Hello Kyle
21+
22+
$ hello Kyle Katie
23+
Hello Kyle and Katie
24+
```
25+
26+
### Installation
27+
28+
Using Conche, the example can be installed using `conche install`.
29+
30+
```shell
31+
$ conche install
32+
```
33+
34+
By default, it will install the tool into `/usr/local`, you can pass in a
35+
custom destination using `--prefix`.
36+
37+
```shell
38+
$ conche install --prefix /usr/local/Cellar/hello/HEAD
39+
```
40+
41+
### Running the tests
42+
43+
```shell
44+
$ conche test
45+
```
46+
47+
### Running `hello` without installing
48+
49+
You can use `conche` to build and run the `hello` example without
50+
installing it to your system as follows:
51+
52+
```shell
53+
$ conche build
54+
$ conche exec hello
55+
```

bin/hello.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
print("Hello Hello")
1+
import Hello
2+
3+
let names = Array(Process.arguments[1 ..< Process.arguments.endIndex])
4+
print(hello(names))

0 commit comments

Comments
 (0)