Fix passing path arguments on first parse.

This commit is contained in:
Marek Fořt 2020-03-21 12:25:09 +01:00
parent ba068b9a4b
commit c5dfa7e46d
4 changed files with 22 additions and 11 deletions

View File

@ -80,7 +80,17 @@ class ScaffoldCommand: NSObject, Command {
func parse(with parser: ArgumentParser, arguments: [String]) throws -> ArgumentParser.Result {
guard arguments.count >= 2 else { throw ScaffoldCommandError.templateNotProvided }
// We want to parse only the name of template, not its arguments which will be dynamically added
let resultArguments = try parser.parse(Array(arguments.prefix(2)))
let templateArguments = Array(arguments.prefix(2))
// Plucking out path argument
let filteredArguments = stride(from: 2, to: arguments.count, by: 2).map {
arguments[$0..<min($0 + 2, arguments.count)]
}
.filter {
$0.first == "--path"
}
.flatMap { Array($0) }
// We want to parse only the name of template, not its arguments which will be dynamically added
let resultArguments = try parser.parse(templateArguments + filteredArguments)
if resultArguments.get(listArgument) != nil {
return try parser.parse(arguments)
@ -108,11 +118,10 @@ class ScaffoldCommand: NSObject, Command {
}
func run(with arguments: ArgumentParser.Result) throws {
guard let templateName = arguments.get(templateArgument) else { throw ScaffoldCommandError.templateNotProvided }
let path = self.path(arguments: arguments)
let templateDirectories = try templatesDirectoryLocator.templateDirectories(at: path)
let shouldList = arguments.get(listArgument) ?? false
if shouldList {
try templateDirectories.forEach {
@ -121,7 +130,9 @@ class ScaffoldCommand: NSObject, Command {
}
return
}
guard let templateName = arguments.get(templateArgument) else { throw ScaffoldCommandError.templateNotProvided }
try verifyDirectoryIsEmpty(path: path)
let templateDirectory = try self.templateDirectory(templateDirectories: templateDirectories,

View File

@ -4,5 +4,6 @@ Feature: Scaffold a project using Tuist
Given that tuist is available
And I have a working directory
Then I copy the fixture ios_app_with_templates into the working directory
Then tuist scaffolds a custom template to TemplateProject named TemplateProject and platform ios
Then content of a file named custom_dir/custom.swift in a directory TemplateProject should be equal to "// this is test TemplateProject content"
Then tuist scaffolds a custom template to TemplateProject named TemplateProject
Then content of a file named TemplateProject/custom.swift in a directory TemplateProject should be equal to "// this is test TemplateProject content"
Then content of a file named TemplateProject/generated.swift in a directory TemplateProject should be equal to "// Generated file with platform: ios and name: TemplateProject\n"

View File

@ -1,8 +1,7 @@
# frozen_string_literal: true
Then(/tuist scaffolds a (.+) template to (.+) named (.+) and platform (.+)/) do |template, path, name, platform|
system("swift", "run", "tuist", "scaffold", "--list")
system("swift", "run", "tuist", "scaffold", template, "--path", File.join(@dir, path), "--attributes", "--name", name, "--platform", platform)
Then(/tuist scaffolds a (.+) template to (.+) named (.+)/) do |template, path, name|
system("swift", "run", "tuist", "scaffold", template, "--path", File.join(@dir, path), "--name", name)
end
Then(/content of a file named (.+) in a directory (.+) should be equal to (.+)/) do |file, dir, content|

View File

@ -66,4 +66,4 @@ DerivedData/
graph.dot
### Templates generated files ###
custom_dir/
TemplateProject/