Add LICENSE

This commit is contained in:
Pedro Piñera 2018-06-28 15:00:33 +02:00
parent ceabe324a3
commit 1dff2ad324
5 changed files with 102 additions and 1 deletions

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) from 2018 Pedro Piñera Buendía
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.

View File

@ -0,0 +1,8 @@
import Utility
protocol Command {
static var command: String { get }
static var overview: String { get }
init(parser: ArgumentParser)
func run(with arguments: ArgumentParser.Result) throws
}

View File

@ -0,0 +1,49 @@
import Basic
import Foundation
import Utility
public final class CommandRegistry {
let parser: ArgumentParser
var commands: [Command] = []
private let processArguments: () -> [String]
public convenience init() {
self.init(processArguments: CommandRegistry.processArguments)
register(command: ReleaseCommand.self)
}
init(processArguments: @escaping () -> [String]) {
parser = ArgumentParser(usage: "<command> <options>",
overview: "Includes a set of tools to work with the project")
self.processArguments = processArguments
}
public static func processArguments() -> [String] {
return Array(ProcessInfo.processInfo.arguments)
}
func register(command: Command.Type) {
commands.append(command.init(parser: parser))
}
public func run() throws {
let parsedArguments = try parse()
try process(arguments: parsedArguments)
}
private func parse() throws -> ArgumentParser.Result {
let arguments = Array(processArguments().dropFirst())
return try parser.parse(arguments)
}
private func process(arguments: ArgumentParser.Result) throws {
guard let subparser = arguments.subparser(parser),
let command = commands.first(where: { type(of: $0).command == subparser }) else {
parser.printUsage(on: stdoutStream)
return
}
try command.run(with: arguments)
}
}

View File

@ -0,0 +1,20 @@
import Basic
import Foundation
import Utility
public class ReleaseCommand: NSObject, Command {
public static let command = "release"
public static let overview = "Releases a new version of xpm"
private let fileManager: FileManager = .default
public required init(parser: ArgumentParser) {
_ = parser.add(subparser: ReleaseCommand.command, overview: ReleaseCommand.overview)
}
public func run(with arguments: ArgumentParser.Result) throws {
try Process.checkNonZeroExit(args: "swift", "build", "--configuration", "release")
}
}

View File

@ -1 +1,4 @@
print("Running tools")
import Foundation
var registry = CommandRegistry()
try registry.run()