Skip to content

Commit

Permalink
Deprecate --template in favor of --templateName
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed Sep 28, 2018
1 parent d327a40 commit 05e0b88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -218,7 +218,7 @@ One rare cases where this might be useful — as opposed to using a config file
Each subcommand generally accepts the same options and syntax, and they mirror the options and parameters from the configuration file:

* `--output FILE` or `-o FILE`: set the file where to write the generated code. If omitted, the generated code will be printed on `stdout`.
* `--template NAME` or `-t NAME`: define the Stencil template to use (by name, see [here for more info](Documentation/templates)) to generate the output.
* `--templateName NAME` or `-n NAME`: define the Stencil template to use (by name, see [here for more info](Documentation/templates)) to generate the output.
* `--templatePath PATH` or `-p PATH`: define the Stencil template to use, using a full path.
* Note: you should specify one and only one template when invoking SwiftGen. You have to use either `-t` or `-p` but should not use both at the same time (it wouldn't make sense anyway and you'll get an error if you try)
* Each command supports multiple input files (or directories where applicable).
Expand Down
18 changes: 15 additions & 3 deletions Sources/SwiftGen/Commander/ParserCLICommands.swift
Expand Up @@ -9,10 +9,20 @@ import PathKit
import StencilSwiftKit
import SwiftGenKit

private let templateNameOption = Option<String>(
// deprecated option
private let deprecatedTemplateNameOption = Option<String>(
"template",
default: "",
flag: "t",
description: """
DEPRECATED, use `--templateName` instead
"""
)

private let templateNameOption = Option<String>(
"templateName",
default: "",
flag: "n",
description: """
The name of the template to use for code generation. \
See `swiftgen templates list` for a list of available names
Expand All @@ -36,18 +46,20 @@ extension ParserCLI {
func command() -> CommandType {
return Commander.command(
outputOption,
deprecatedTemplateNameOption,
templateNameOption,
templatePathOption,
paramsOption,
VariadicArgument<Path>("PATH", description: self.pathDescription, validator: pathsExist)
) { output, templateName, templatePath, parameters, paths in
) { output, oldTemplateName, templateName, templatePath, parameters, paths in
try ErrorPrettifier.execute {
let parser = try self.parserType.init(options: [:]) { msg, _, _ in
logMessage(.warning, msg)
}
try parser.parse(paths: paths)

let templateRef = try TemplateRef(templateShortName: templateName,
let resolvedlTemplateName = templateName.isEmpty ? oldTemplateName : templateName
let templateRef = try TemplateRef(templateShortName: resolvedlTemplateName,
templateFullPath: templatePath)
let templateRealPath = try templateRef.resolvePath(forSubcommand: self.templateFolder)

Expand Down

0 comments on commit 05e0b88

Please sign in to comment.