Skip to content

Commit

Permalink
Starting to move into a more formal structure
Browse files Browse the repository at this point in the history
  • Loading branch information
wess committed Nov 29, 2016
1 parent 33cfbda commit 1b44c45
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 81 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

all: run
all: version

build:
@swift build
@swift build

install:
@mv .build/release/task /usr/local/bin/
Expand All @@ -16,9 +16,14 @@ xcode:
@swift package generate-xcodeproj

run: build
@.build/debug/task testing
@.build/debug/task

release: clean
@swift build --configuration release


help: build
@.build/debug/task help

version: build
@.build/debug/task version

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ let package = Package(
name: "task",

targets: [
Target(name: "task", dependencies: []),
Target(name: "task", dependencies: ["middleware",]),
Target(name: "middleware"),
],

dependencies: [
Expand Down
37 changes: 0 additions & 37 deletions Sources/main.swift

This file was deleted.

6 changes: 6 additions & 0 deletions Sources/middleware/middleware.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import Foundation

struct Middleware {

}
39 changes: 0 additions & 39 deletions Sources/task.swift

This file was deleted.

Empty file.
16 changes: 16 additions & 0 deletions Sources/task/commands/extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// extensions.swift
// task
//
// Created by Wesley Cope on 11/28/16.
//
//

import Foundation
import SwiftCLI

extension Equatable where Self : Command {}

public func ==(lhs:Command, rhs:Command) -> Bool {
return lhs.name.lowercased() == rhs.name.lowercased()
}
50 changes: 50 additions & 0 deletions Sources/task/commands/init.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// init.swift
// Task
//
// Created by Wesley Cope on 11/28/16.
//
//

import Foundation
import SwiftCLI
import PathKit
import Rainbow

public class InitCommand : Command {
public let name = "init"
public let signature = ""
public let shortDescription = "Creates an initial Taskfile in the current directory"

private var today:String {
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/YY"

return formatter.string(from: Date())
}


private let template = ["// Created: {DATE}",
"",
"import task",
"",
"task(\"hello\") { arguments in",
"",
" print(\"world\")",
"",
"}",
"\n",]

public func execute(arguments: CommandArguments) throws {
let path = Path.current + Path("Taskfile")
let taskfile = template.joined(separator: "\n").replacingOccurrences(of: "{DATE}", with: today)

guard let data = taskfile.data(using: .utf8) else {
fatalError("Unable to write initial Taskfile")
}

try path.write(data)
}
}


31 changes: 31 additions & 0 deletions Sources/task/commands/setup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// setup.swift
// Task
//
// Created by Wesley Cope on 11/28/16.
//
//

import Foundation
import SwiftCLI
import PathKit
import Rainbow

public class InitCommand : Command {
public let name = "setup"
public let signature = ""
public let shortDescription = "Initial setup or update for Task"

public func execute(arguments: CommandArguments) throws {
let path = Path.current + Path("Taskfile")
let taskfile = template.joined(separator: "\n").replacingOccurrences(of: "{DATE}", with: today)

guard let data = taskfile.data(using: .utf8) else {
fatalError("Unable to write initial Taskfile")
}

try path.write(data)
}
}


23 changes: 23 additions & 0 deletions Sources/task/commands/version.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// version.swift
// task
//
// Created by Wesley Cope on 11/28/16.
//
//

import Foundation
import SwiftCLI
import Rainbow

public class VersionCommand : Command {
public let name = "version"
public let signature = ""
public let shortDescription = "Prints the current version of " + Task.name.bold

public func execute(arguments: CommandArguments) throws {
print(Task.name.green.bold + " Version: " + Task.version.bold)
}
}


11 changes: 11 additions & 0 deletions Sources/task/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// main.swift
// task
//
// Created by Wesley Cope on 11/28/16.
//
//

Task().run()


File renamed without changes.
Loading

0 comments on commit 1b44c45

Please sign in to comment.