Init commit.
This commit is contained in:
commit
aa72b55cb3
|
@ -0,0 +1,7 @@
|
||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
||||||
|
|
||||||
|
# Ignore editor settings
|
||||||
|
.vscode/
|
|
@ -0,0 +1,10 @@
|
||||||
|
image: kylef/swiftenv
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- swiftenv install https://swift.org/builds/swift-3.1-release/ubuntu1604/swift-3.1-RELEASE/swift-3.1-RELEASE-ubuntu16.04.tar.gz
|
||||||
|
|
||||||
|
test:
|
||||||
|
script:
|
||||||
|
- swift build
|
||||||
|
tags:
|
||||||
|
- vapor
|
|
@ -0,0 +1,32 @@
|
||||||
|
#
|
||||||
|
# Be sure to run `pod lib lint FileKit.podspec' to ensure this is a
|
||||||
|
# valid spec before submitting.
|
||||||
|
#
|
||||||
|
# Any lines starting with a # are optional, but their use is encouraged
|
||||||
|
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
|
||||||
|
#
|
||||||
|
|
||||||
|
Pod::Spec.new do |s|
|
||||||
|
s.name = 'FileKit'
|
||||||
|
s.version = '0.1.0'
|
||||||
|
s.summary = 'A unix-command like file manager written in Swift.'
|
||||||
|
|
||||||
|
# This description is used to generate tags and improve search results.
|
||||||
|
# * Think: What does it do? Why did you write it? What is the focus?
|
||||||
|
# * Try to keep it short, snappy and to the point.
|
||||||
|
# * Write the description between the DESC delimiters below.
|
||||||
|
# * Finally, don't worry about the indent, CocoaPods strips it!
|
||||||
|
|
||||||
|
s.description = <<-DESC
|
||||||
|
TODO: Add long description of the pod here.
|
||||||
|
DESC
|
||||||
|
|
||||||
|
s.homepage = 'https://git.happinesslab.xyz/PINNA/FileKit'
|
||||||
|
s.license = { :type => 'ISC', :file => 'LICENSE' }
|
||||||
|
s.author = { 'shotastage' => 'hornet.live.mf@gmail.com' }
|
||||||
|
s.source = { :git => 'https://git.happinesslab.xyz/PINNA/FileKit.git', :tag => s.version.to_s }
|
||||||
|
|
||||||
|
s.ios.deployment_target = '9.0'
|
||||||
|
|
||||||
|
s.source_files = 'Sources/**/*'
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"autoPin": true,
|
||||||
|
"pins": [
|
||||||
|
|
||||||
|
],
|
||||||
|
"version": 1
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "FileKit"
|
||||||
|
)
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 🗂 FileKit
|
||||||
|
|
||||||
|
FileKit is file utilities for Swift.
|
||||||
|
It enables to mange files or directories efficiently and easily.
|
||||||
|
|
||||||
|
# ⌘ APIs
|
||||||
|
|
||||||
|
| Function | |
|
||||||
|
|:--|:--|
|
||||||
|
| `func pwd() -> String` | Get current directory path as a string.|
|
||||||
|
| `func home() -> Strings` | Get home directory path.|
|
||||||
|
| `func isFile(file: String) -> Bool` | Check the file exists or not. |
|
||||||
|
| `func isDir(path: String) -> Bool ` | Check the directory exists or not.|
|
||||||
|
| `func cd(path: String) throws`| Change directory like a `cd` command.|
|
||||||
|
| `func mkdir(path: String) throws` | Make directory. |
|
||||||
|
| `func rm(target: String) throws`| Remove directory or file. |
|
||||||
|
| `func mv(from fromPath: String, to toPath: String)`| Move file or directory.|
|
||||||
|
| `func touch(_ path: String) throws`| Create empty file. |
|
|
@ -0,0 +1,7 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum FileError: Error {
|
||||||
|
case NotExists
|
||||||
|
case PermissionError
|
||||||
|
case Unkown(String)
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
extension FileKit: BasicFileCommands {
|
||||||
|
public func cd(_ path: String) throws {
|
||||||
|
if !FileKit.fm.changeCurrentDirectoryPath(path) {
|
||||||
|
if !FileKit.fm.fileExists(atPath: path) {
|
||||||
|
throw FileError.NotExists
|
||||||
|
} else {
|
||||||
|
throw FileError.Unkown("Failed to change current direcotry.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public func mkdir(_ path: String) throws {
|
||||||
|
try FileKit.fm.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func rm(_ target: String) throws {
|
||||||
|
try FileKit.fm.removeItem(atPath: target)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func mv(from fromPath: String, to toPath: String) throws {
|
||||||
|
try FileKit.fm.moveItem(atPath: fromPath, toPath: toPath)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
// Show file information
|
||||||
|
extension FileKit {
|
||||||
|
public func pwd() -> String {
|
||||||
|
let path = FileKit.fm.currentDirectoryPath
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
public func home() -> String {
|
||||||
|
let path = NSHomeDirectory()
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check file or directory existence
|
||||||
|
extension FileKit {
|
||||||
|
public var isFile: Bool {
|
||||||
|
return FileKit.fm.fileExists(atPath: self.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
public var isDir: Bool {
|
||||||
|
return FileKit.fm.fileExists(atPath: self.path)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
extension FileKit {
|
||||||
|
public func touch(_ path: String) throws {
|
||||||
|
let empty = ""
|
||||||
|
do {
|
||||||
|
try empty.write(toFile: path, atomically: true, encoding: String.Encoding.utf8)
|
||||||
|
} catch let error as NSError {
|
||||||
|
print("failed to write: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public class FileKit {
|
||||||
|
|
||||||
|
// Define typealias
|
||||||
|
public typealias Path = String
|
||||||
|
|
||||||
|
// Path
|
||||||
|
internal var path: String
|
||||||
|
|
||||||
|
// Foundational File Manager
|
||||||
|
internal static var fm = FileManager.default
|
||||||
|
|
||||||
|
|
||||||
|
// Initializers
|
||||||
|
public init() {
|
||||||
|
self.path = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
public init(_ path: String) {
|
||||||
|
self.path = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Internet file management
|
||||||
|
extension FileKit {
|
||||||
|
public func curlO(url: String) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public protocol FileKitProtocol {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
protocol BasicFileCommands {
|
||||||
|
func cd(_ path: String) throws
|
||||||
|
func mkdir(_ path: String) throws
|
||||||
|
func rm(_ target: String) throws
|
||||||
|
func mv(from fromPath: String, to toPath: String) throws
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
|
struct UbuntuFileSystem {
|
||||||
|
let formatType = "ext4"
|
||||||
|
let root = "/"
|
||||||
|
let settings = "/etc"
|
||||||
|
let optional = "/opt"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import Foundation
|
||||||
|
import XCTest
|
||||||
|
@testable import FileKit // Test target
|
||||||
|
|
||||||
|
public func FileKitTest() {
|
||||||
|
// NO TEST NOW
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
class FileKitTests: XCTestCase {
|
||||||
|
func testRunSpec() {
|
||||||
|
testFileKit()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
#if os(Linux)
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue