[go: up one dir, main page]

Skip to content

Commit

Permalink
added init command
Browse files Browse the repository at this point in the history
  • Loading branch information
gurhub committed Nov 19, 2020
1 parent 3a36e48 commit a6e3422
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Formula/surmagic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class Surmagic < Formula
license "GPL-3.0"

def install
bin.install("surmagic")
bin.install("bin/surmagic")
end
end
62 changes: 59 additions & 3 deletions surmagic → bin/surmagic
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,53 @@
import Foundation

// MARK: - Main Logic

mainLogic()

// MARK: - Methods

private func parseArguments() {
if (CommandLine.argc > 1) {
let firstArg = CommandLine.arguments[1]

switch Command(rawValue: firstArg) {
case .initialize:
createTemplateFiles()
exit(1)
default:
showHowToUseAndExit()
}
}
}

/// Prints how to use documentation and exits.
private func showHowToUseAndExit() {
print("Unknown argument call.")
exit(1)
}

/// cp -a /source/. /dest/
/// Creates template files.
private func createTemplateFiles() {

create("./Surmagic")

let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/bin/env")
let source = "./Template/Surmagic/Surfile"
task.arguments = ["cp", "-iv", source, "./Surmagic/."]

do {
try task.run()
task.waitUntilExit()

print(Colors.green + "\n 🚚 Initialized default files in the directory.\n" + Colors.reset)
} catch {
exit(with: nil)
}
}

/// Removes files in giving directory.
private func remove(_ directory: String) {
let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/bin/env")
Expand All @@ -30,6 +72,7 @@ private func remove(_ directory: String) {
}
}

/// Creates a directory in giving directory.
private func create(_ directory: String) {
let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/bin/env")
Expand Down Expand Up @@ -187,6 +230,8 @@ private func openOutputPath(_ directory: String) {
/// Parse the Surfile (plist) file for the parameters.
private func mainLogic() {
do {
parseArguments()

//let cwd = FileManager.default.currentDirectoryPath
let path = "./Surmagic/Surfile"
let plistURL = URL(fileURLWithPath: path)
Expand Down Expand Up @@ -219,7 +264,7 @@ private func exit(with error: Error?) {
if let error = error {
errorMessage = "\(error.localizedDescription)"
} else {
errorMessage = "Error 109"
errorMessage = "Error 109."
}

print("\(errorMessage)")
Expand Down Expand Up @@ -311,7 +356,8 @@ public class Surfile: Codable {
}
}

/// Enums
// MARK: - Enums

public enum SDK: String, Codable {
case iOS
case iOSSimulator
Expand All @@ -334,6 +380,16 @@ public enum SDK: String, Codable {
}
}

public enum Command: String, Codable {
case initialize = "init"

var description: String {
switch self {
case .initialize: return "init"
}
}
}

public class Target: Codable {

// MARK: Types
Expand Down

0 comments on commit a6e3422

Please sign in to comment.