@@ -77,6 +77,7 @@ extension SwiftPackageTool {
77
77
if let index = subCommands. firstIndex ( where: { $0 == Init . self } ) {
78
78
subCommands. insert ( Create . self, at: index + 1 )
79
79
subCommands. insert ( AddTemplate . self, at: index + 2 )
80
+ subCommands. insert ( UpdateTemplate . self, at: index + 3 )
80
81
}
81
82
}
82
83
@@ -223,7 +224,7 @@ extension SwiftPackageTool {
223
224
224
225
func run( _ swiftTool: SwiftTool ) throws {
225
226
guard let cwd = localFileSystem. currentWorkingDirectory else {
226
- throw InternalError ( " Could not find the current working directroy . " )
227
+ throw InternalError ( " Could not find the current working directory . " )
227
228
}
228
229
229
230
guard let configPath = try swiftTool. getConfigPath ( ) else {
@@ -267,7 +268,7 @@ extension SwiftPackageTool {
267
268
268
269
func run( _ swiftTool: SwiftTool ) throws {
269
270
guard let cwd = localFileSystem. currentWorkingDirectory else {
270
- throw InternalError ( " Could not find the current working directroy . " )
271
+ throw InternalError ( " Could not find the current working directory . " )
271
272
}
272
273
273
274
guard let configPath = try swiftTool. getConfigPath ( ) else {
@@ -315,15 +316,17 @@ extension SwiftPackageTool {
315
316
throw InternalError ( " Could not get the current working directory " )
316
317
}
317
318
318
- if localFileSystem. exists ( AbsolutePath ( url) ) {
319
- let currentTemplateLocation = AbsolutePath ( url)
320
- let templateDirectory = configPath. appending ( components: " templates " , " new-package " , url)
321
-
322
- guard localFileSystem. exists ( currentTemplateLocation) && localFileSystem. isDirectory ( currentTemplateLocation) else {
323
- throw InternalError ( " Template folder \( url) could not be found in: \( cwd) " )
319
+ if let path = try ? AbsolutePath ( validating: url) {
320
+ if localFileSystem. exists ( path) {
321
+ let currentTemplateLocation = path
322
+ let templateDirectory = configPath. appending ( components: " templates " , " new-package " , url)
323
+
324
+ guard localFileSystem. exists ( currentTemplateLocation) && localFileSystem. isDirectory ( currentTemplateLocation) else {
325
+ throw InternalError ( " Template folder \( url) could not be found in: \( cwd) " )
326
+ }
327
+
328
+ try localFileSystem. copy ( from: currentTemplateLocation, to: templateDirectory)
324
329
}
325
-
326
- try localFileSystem. copy ( from: currentTemplateLocation, to: templateDirectory)
327
330
} else {
328
331
let templatePath : AbsolutePath
329
332
let provider = GitRepositoryProvider ( )
@@ -341,6 +344,32 @@ extension SwiftPackageTool {
341
344
}
342
345
}
343
346
347
+ struct UpdateTemplate : SwiftCommand {
348
+ static let configuration = CommandConfiguration (
349
+ abstract: " Update template from remote " )
350
+
351
+ @OptionGroup ( _hiddenFromHelp: true )
352
+ var swiftOptions : SwiftToolOptions
353
+
354
+ @Argument ( help: " Template to update " )
355
+ var templateName : String
356
+
357
+ func run( _ swiftTool: SwiftTool ) throws {
358
+ guard let configPath = try swiftTool. getConfigPath ( ) else {
359
+ throw InternalError ( " Could not find config path " )
360
+ }
361
+
362
+ guard localFileSystem. exists ( configPath. appending ( components: " templates " , " new-package " , templateName) ) else {
363
+ throw InternalError ( " Could not find \( templateName) " )
364
+ }
365
+
366
+ let provider = GitRepositoryProvider ( )
367
+ let templatePath = configPath. appending ( components: " templates " , " new-package " , templateName)
368
+
369
+ try provider. pull ( repository: RepositorySpecifier ( url: templatePath. pathString) , to: templatePath)
370
+ }
371
+ }
372
+
344
373
struct Format : SwiftCommand {
345
374
static let configuration = CommandConfiguration (
346
375
commandName: " _format " )
0 commit comments