1- import Foundation
1+ //
2+ // main.swift
3+ //
4+ //
5+ // Created by Jeff Lebrun on 0/00/20.
6+ //
7+
28import ArgumentParser
3- import Rainbow
49import Files
10+ import Foundation
511import LFSPointersKit
12+ import Rainbow
613
714let jsonStructure = """
815[
@@ -34,16 +41,16 @@ struct LFSPointersCommand: ParsableCommand {
3441 discussion: " JSON STRUCTURE: \n \( jsonStructure) " ,
3542 version: " 3.0.0 "
3643 )
37-
44+
3845 @Flag ( name: . shortAndLong, help: " Whether to display verbose output. " )
3946 var verbose : Bool = false
40-
47+
4148 @Flag ( name: . customLong( " silent " ) , help: " Don't print to standard output or standard error. " )
4249 var s : Bool = false
43-
50+
4451 @Flag ( name: . shortAndLong, help: " Repeat this process in all directories. " )
4552 var recursive : Bool = false
46-
53+
4754 @Flag ( name: . shortAndLong, help: " Convert all files to pointers (USE WITH CAUTION!). " )
4855 var all : Bool = false
4956
@@ -69,20 +76,20 @@ struct LFSPointersCommand: ParsableCommand {
6976 transform: URL . init ( fileURLWithPath: )
7077 )
7178 var backupDirectory : URL ? = nil
72-
79+
7380 @Argument (
7481 help: " The directory which contains the files you want to convert to LFS pointers. " ,
7582 completion: . directory,
7683 transform: URL . init ( fileURLWithPath: )
7784 )
7885 var directory : URL
79-
86+
8087 @Argument (
8188 help: " A list of paths to files, relative to the current directory, that represent files to be converted. You can use your shell's regular expression support to pass in a list of files. " ,
8289 completion: . file( )
8390 )
8491 var files : [ String ] = [ ]
85-
92+
8693 mutating func validate( ) throws {
8794 // Verify the directory actually exists.
8895 guard FileManager ( ) . fileExists ( atPath: directory. path) else {
@@ -97,22 +104,22 @@ struct LFSPointersCommand: ParsableCommand {
97104 }
98105 }
99106 }
100-
107+
101108 func run( ) throws {
102109 var silent = false
103-
110+
104111 if s {
105112 silent = true
106113 }
107-
114+
108115 if json {
109116 silent = true
110117 }
111-
118+
112119 if !color {
113120 Rainbow . enabled = false
114121 }
115-
122+
116123 let printClosure : ( URL , Status ) -> Void = { url, status in
117124 switch status {
118125 case let . appending( pointer) :
@@ -122,17 +129,17 @@ struct LFSPointersCommand: ParsableCommand {
122129 } else if !silent {
123130 print ( " Appending pointer to file \" \( file. name) \" ... " )
124131 }
125-
132+
126133 case let . error( error) :
127134 let file = try ! File ( path: url. path)
128-
135+
129136 if self . verbose && !silent {
130137 if self . color {
131138 fputs ( " Could not convert \" \( file. name) \" to a pointer. \n Git LFS error: \( error) \n " . red, stderr)
132139 } else {
133140 fputs ( " Could not convert \" \( file. name) \" to a pointer. \n Git LFS error: \( error) \n " , stderr)
134141 }
135-
142+
136143 } else if !silent {
137144 if self . color {
138145 fputs ( " Could not convert \" \( file. name) \" to a pointer. " . red, stderr)
@@ -141,22 +148,22 @@ struct LFSPointersCommand: ParsableCommand {
141148 }
142149 }
143150 break
144-
151+
145152 case . generating:
146153 let file = try ! File ( path: url. path)
147-
154+
148155 if !silent && self . verbose {
149156 print ( " Converting \" \( file. name) \" to pointer... \n " )
150157 } else if !silent {
151158 print ( " Converting \" \( file. name) \" to pointer... \n " )
152159 }
153160 case let . regexDoesntMatch( regex) :
154161 let file = try ! File ( path: url. path)
155-
162+
156163 if !silent && self . verbose {
157164 print ( " File name \" \( file. name) \" does not match regular expression \" \( regex. pattern) \" , continuing... " )
158165 }
159-
166+
160167 case let . writing( pointer) :
161168 let file = try ! File ( path: url. path)
162169 if self . verbose && !silent {
@@ -166,7 +173,7 @@ struct LFSPointersCommand: ParsableCommand {
166173 }
167174 }
168175 }
169-
176+
170177 do {
171178
172179 if all {
@@ -180,13 +187,13 @@ struct LFSPointersCommand: ParsableCommand {
180187 Foundation . exit ( 0 )
181188 }
182189 }
183-
190+
184191 if let bd = backupDirectory {
185192 do {
186193 if !silent {
187194 print ( " Copying files to backup directory... " )
188195 }
189-
196+
190197 // Copy the specified directory into the backup directory.
191198 try Folder ( path: directory. path) . copy ( to: Folder ( path: bd. path) )
192199 } catch {
@@ -204,22 +211,22 @@ struct LFSPointersCommand: ParsableCommand {
204211 )
205212 }
206213 }
207-
214+
208215 Foundation . exit ( 4 )
209216 }
210217 }
211-
218+
212219 if all {
213220 let pointers = try LFSPointer . pointers (
214221 forDirectory: directory,
215222 searchType: . all,
216223 recursive: recursive,
217224 statusClosure: printClosure
218225 )
219-
226+
220227 if !json {
221228 pointers. forEach ( { p in
222-
229+
223230 do {
224231 try p. write (
225232 toFile: URL ( fileURLWithPath: p. filePath) ,
@@ -240,7 +247,7 @@ struct LFSPointersCommand: ParsableCommand {
240247 fputs ( " Unable to overwrite file \" \( p. filename) \" . Error: \( error) " , stderr)
241248 }
242249 }
243-
250+
244251 } )
245252 } else {
246253 do {
@@ -261,10 +268,10 @@ struct LFSPointersCommand: ParsableCommand {
261268 recursive: recursive,
262269 statusClosure: printClosure
263270 )
264-
271+
265272 if !json {
266273 pointers. forEach ( { p in
267-
274+
268275 do {
269276 try p. write (
270277 toFile: URL ( fileURLWithPath: p. filePath) ,
@@ -286,7 +293,7 @@ struct LFSPointersCommand: ParsableCommand {
286293 fputs ( " Unable to overwrite file \" \( p. filename) \" . Error: \( error) " , stderr)
287294 }
288295 }
289-
296+
290297 } )
291298 } else {
292299 do {
@@ -299,7 +306,7 @@ struct LFSPointersCommand: ParsableCommand {
299306 }
300307
301308 }
302-
309+
303310 } catch let error {
304311 if !silent {
305312
@@ -310,10 +317,10 @@ struct LFSPointersCommand: ParsableCommand {
310317 }
311318
312319 }
313-
320+
314321 Foundation . exit ( 2 )
315322 }
316-
323+
317324 if !silent {
318325
319326 if self . color {
0 commit comments