Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SwiftCLI #667

Merged
merged 6 commits into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"repositoryURL": "https://github.com/jakeheis/SwiftCLI.git",
"state": {
"branch": null,
"revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf",
"version": "5.2.2"
"revision": "ba2268e67c07b9f9cfbc0801385e6238b36255eb",
"version": "5.3.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let package = Package(
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.0"),
.package(url: "https://github.com/onevcat/Rainbow.git", from: "3.0.0"),
.package(url: "https://github.com/tuist/xcodeproj.git", .exact("7.1.0")),
.package(url: "https://github.com/jakeheis/SwiftCLI.git", .exact("5.2.2")),
.package(url: "https://github.com/jakeheis/SwiftCLI.git", .exact("5.3.2")),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make this from, incase other packages using XcodeGen also use SwiftCLI

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use upToNextMinor(from:) than from. Because SwiftCLI brought breaking change when minor versions are updated.

],
targets: [
.target(name: "XcodeGen", dependencies: [
Expand Down
20 changes: 0 additions & 20 deletions Sources/XcodeGenCLI/CommandRouter.swift

This file was deleted.

15 changes: 14 additions & 1 deletion Sources/XcodeGenCLI/XcodeGenCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import ProjectSpec
import SwiftCLI

public class XcodeGenCLI {
private struct Manipulator: ArgumentListManipulator {
let commandName: String
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this defaultCommand


func manipulate(arguments: ArgumentList) {
if !arguments.hasNext() || arguments.nextIsOption() {
arguments.manipulate { existing in
return [commandName] + existing
}
}
}
}

let cli: CLI

Expand All @@ -15,7 +26,9 @@ public class XcodeGenCLI {
description: "Generates Xcode projects",
commands: [generateCommand]
)
cli.parser = Parser(router: CommandRouter(defaultCommand: generateCommand))
let manipulator = Manipulator(commandName: generateCommand.name)
cli.argumentListManipulators.insert(manipulator, at: 0)
cli.parser.routeBehavior = .searchWithFallback(generateCommand)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this new routeBehaviour replace the need for the Manipulator? The purpose of that was to make generate the default command

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it works fine with just the routeBehaviour

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried getting rid of any custom manipulators. However, behavior is changed. So it is needed.

$ swift run xcodegen # works fine
$ swift run xcodegen generate # behaviors are changed.

Usage: xcodegen [options]

Generate an Xcode project from a spec

Options:
  --cache-path <value>     Where the cache file will be loaded from and save to. Defaults to ~/.xcodegen/cache/{SPEC_PATH_HASH}
  -c, --use-cache          Use a cache for the xcodegen spec. This will prevent unnecessarily generating the project if nothing has changed
  -h, --help               Show help information
  -p, --project <value>    The path to the directory where the project should be generated. Defaults to the directory the spec is in. The filename is defined in the project spec
  -q, --quiet              Suppress all informational and success output
  -s, --spec <value>       The path to the project spec file. Defaults to project.yml

Error: command requires exactly 0 arguments

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried again, it will works as you said. Manipulators are not needed.

}

public func execute(arguments: [String]? = nil) {
Expand Down