-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix swift package init --help printout #3407
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
Changes from 2 commits
961425b
a15e484
876e69a
b57a27f
6483303
2f806ef
72e7009
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,7 +163,7 @@ extension SwiftPackageTool { | |
@OptionGroup() | ||
var swiftOptions: SwiftToolOptions | ||
|
||
@Option() | ||
@Option(help: "json | text") | ||
var type: DescribeMode = .text | ||
|
||
func run(_ swiftTool: SwiftTool) throws { | ||
|
@@ -190,22 +190,25 @@ extension SwiftPackageTool { | |
} | ||
} | ||
|
||
struct Init: SwiftCommand { | ||
static let configuration = CommandConfiguration( | ||
public struct Init: SwiftCommand { | ||
public static let configuration = CommandConfiguration( | ||
abstract: "Initialize a new package") | ||
|
||
@OptionGroup() | ||
@OptionGroup(_hiddenFromHelp: true) | ||
var swiftOptions: SwiftToolOptions | ||
|
||
@Option(name: .customLong("type")) | ||
@Option(name: .customLong("type"), help: "Package type: empty | library | executable | system-module | manifest") | ||
var initMode: InitPackage.PackageType = .library | ||
|
||
@Option(name: .customLong("name"), help: "Provide custom package name") | ||
var packageName: String? | ||
|
||
|
||
public init() {} | ||
|
||
func run(_ swiftTool: SwiftTool) throws { | ||
// FIXME: Error handling. | ||
let cwd = localFileSystem.currentWorkingDirectory! | ||
guard let cwd = localFileSystem.currentWorkingDirectory else { | ||
throw StringError("Could not find the current working directory") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. throw InternalError in such case, as it would assert in debug mode which is what we want in this failure case |
||
} | ||
|
||
let packageName = self.packageName ?? cwd.basename | ||
let initPackage = try InitPackage( | ||
|
@@ -343,6 +346,9 @@ extension SwiftPackageTool { | |
} | ||
|
||
struct DumpSymbolGraph: SwiftCommand { | ||
static let configuration = CommandConfiguration( | ||
abstract: "Dump Symbol Graph") | ||
|
||
@OptionGroup() | ||
var swiftOptions: SwiftToolOptions | ||
|
||
|
@@ -472,7 +478,7 @@ extension SwiftPackageTool { | |
@OptionGroup() | ||
var swiftOptions: SwiftToolOptions | ||
|
||
@Option() | ||
@Option(help: "text | dot | json | flatlist") | ||
var format: ShowDependenciesMode = .text | ||
|
||
func run(_ swiftTool: SwiftTool) throws { | ||
|
@@ -489,7 +495,7 @@ extension SwiftPackageTool { | |
@OptionGroup() | ||
var swiftOptions: SwiftToolOptions | ||
|
||
@Option() | ||
@Option(help: "text | dot | json | flatlist") | ||
var format: ShowDependenciesMode = .text | ||
|
||
@Flag(help: "Set tools version of package to the current tools version in use") | ||
|
@@ -908,7 +914,7 @@ extension SwiftPackageTool { | |
@OptionGroup() | ||
var swiftOptions: SwiftToolOptions | ||
|
||
@Argument() | ||
@Argument(help: "generate-bash-script | generate-zsh-script |\ngenerate-fish-script | list-dependencies | list-executables") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the argument parser library enumerate the enum options instead of having to explicitly spell them like this? cc @natecook1000 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe with |
||
var mode: Mode | ||
|
||
func run(_ swiftTool: SwiftTool) throws { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import Xcodeproj | |
import PackageModel | ||
import SourceControl | ||
import SPMTestSupport | ||
import ArgumentParserTestHelpers | ||
import TSCUtility | ||
import Workspace | ||
|
||
|
@@ -48,6 +49,22 @@ final class PackageToolTests: XCTestCase { | |
XCTAssert(stdout.contains("Swift Package Manager"), "got stdout:\n" + stdout) | ||
} | ||
|
||
func testInitHelp() throws { | ||
AssertHelp(for: Commands.SwiftPackageTool.Init.self, equals: """ | ||
OVERVIEW: Initialize a new package | ||
|
||
USAGE: init [<options>] --enable-index-store | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --enable-index-store ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's weird, but it does go away when they're all transitioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another point is that I dont think its scalable to string match the the entire output of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't have to be for all the commands, I think it would be enough to have tests for the most popular commands: e.g.
|
||
|
||
OPTIONS: | ||
--type <type> Package type: empty | library | executable | | ||
system-module | manifest (default: library) | ||
--name <name> Provide custom package name | ||
-h, --help Show help information. | ||
|
||
""" | ||
) | ||
} | ||
|
||
func testNetrcSupportedOS() throws { | ||
func verifyUnsupportedOSThrows() { | ||
do { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to use
AssertHelp
we need access to the commands.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use
@testable import
to expose internal structures and functions for testing purposes. that is better than exposing more surface area in the public API.