Skip to content

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

Merged
merged 7 commits into from
May 3, 2021
Merged

Conversation

miggs597
Copy link
Contributor

Depends on this PR

Fixes swift package init --help to only show help for init
This is a major UI improvement as it allows the user to focus on the help that is solely relevant to init, and not get overwhelmed with other options.

rdar://76116106

@tomerd
Copy link
Contributor

tomerd commented Apr 15, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor

tomerd commented Apr 15, 2021

@natecook1000 ptal

Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

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

Thanks @miggs597, this is great!

So with the custom mirror, does this still depend on the ArgumentParser PR? Or are both needed, i.e. even with the ArgumentParser PR, will the custom mirror continue to be needed?

Comment on lines 200 to 201

static let includeSuperCommandInHelp = false
Copy link
Member

Choose a reason for hiding this comment

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

We decided against requiring this bit for the ArgumentParser change.

Suggested change
static let includeSuperCommandInHelp = false

All of our subcommands need fixing. This is a demo of what fixing all the commands would look like

Also includes some fillings for `Options()` that didn't have any help
@miggs597
Copy link
Contributor Author

To help us catch any possible regressions it would be nice to leverage AssertHelp.
PR

@@ -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")
Copy link
Contributor

@tomerd tomerd Apr 22, 2021

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe with ExpressibleByArgument, I know that it's responsible for filling in default: x

// FIXME: Error handling.
let cwd = localFileSystem.currentWorkingDirectory!
guard let cwd = localFileSystem.currentWorkingDirectory else {
throw StringError("Could not find the current working directory")
Copy link
Contributor

Choose a reason for hiding this comment

The 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

@@ -190,22 +190,25 @@ extension SwiftPackageTool {
}
}

struct Init: SwiftCommand {
static let configuration = CommandConfiguration(
public struct Init: SwiftCommand {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@tomerd tomerd Apr 22, 2021

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.

AssertHelp(for: Commands.SwiftPackageTool.Init.self, equals: """
OVERVIEW: Initialize a new package

USAGE: init [<options>] --enable-index-store
Copy link
Contributor

Choose a reason for hiding this comment

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

--enable-index-store ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

but it does go away when they're all transitioned. what does that mean?

Copy link
Contributor

@tomerd tomerd Apr 22, 2021

Choose a reason for hiding this comment

The 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 --help for each command. did you intend to add such tests to all commands or just this one as an indicator for the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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. swift run, swift build, swift test

--enable-index-store goes away once all the commands have the option group hidden. In my initial testing that's when I noticed that it would go away.

@tomerd tomerd added the WIP Work in progress label Apr 22, 2021
@miggs597
Copy link
Contributor Author

@swift-ci please smoke test

Includes the new constructor that we need
@@ -358,7 +358,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// The 'swift-argument-parser' version declared here must match that
// used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
// dependency version changes here with those projects.
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.3.1")),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
Copy link
Contributor

Choose a reason for hiding this comment

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

please work @shahmishal to also update the toolchain CI definition

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this also needs to be coordinated with https://github.com/apple/swift-driver/blob/main/Package.swift#L134

cc @artemcm

return .on
case .disableIndexStore:
return .off
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this changes is a good one but we should do it in a separate PR

}

@Flag(help: "Enable or disable indexing-while-building feature")
var indexStoreMode: StoreMode = .autoIndexStore
Copy link
Contributor

Choose a reason for hiding this comment

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

this changes is a good one but we should do it in a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what fixes USAGE: init [<options>] --enable-index-store preventing the index store from being printed out, should it still be another PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes please

@@ -12,7 +12,7 @@ import XCTest
import Foundation

import TSCBasic
import Commands
@testable import Commands
Copy link
Contributor

Choose a reason for hiding this comment

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

used?

@miggs597
Copy link
Contributor Author

Updated Toolchain
@swift-ci please smoke test

@miggs597
Copy link
Contributor Author

swiftlang/swift/pull/37113
@swift-ci please smoke test

@miggs597
Copy link
Contributor Author

@miggs597
Copy link
Contributor Author

@miggs597
Copy link
Contributor Author

@miggs597
Copy link
Contributor Author

miggs597 commented May 3, 2021

@neonichu neonichu merged commit a52d4d8 into swiftlang:main May 3, 2021
miggs597 added a commit that referenced this pull request May 4, 2021
* Fix --help printout

* What a fixed --help would look like

All of our subcommands need fixing. This is a demo of what fixing all the commands would look like

Also includes some fillings for `Options()` that didn't have any help

* Testable import, and throw InternalError

* Updated all remaining commands

* Bump Swift-Argument-Parser

Includes the new constructor that we need

* Reverted import of Commands

* Reverted indexStore, to be implemented in separate pr

Co-authored-by: Miguel Perez <[email protected]>
(cherry picked from commit a52d4d8)
miggs597 added a commit to miggs597/swift-package-manager that referenced this pull request May 4, 2021
* Fix --help printout

* What a fixed --help would look like

All of our subcommands need fixing. This is a demo of what fixing all the commands would look like

Also includes some fillings for `Options()` that didn't have any help

* Testable import, and throw InternalError

* Updated all remaining commands

* Bump Swift-Argument-Parser

Includes the new constructor that we need

* Reverted import of Commands

* Reverted indexStore, to be implemented in separate pr

Co-authored-by: Miguel Perez <[email protected]>
(cherry picked from commit a52d4d8)
miggs597 added a commit to miggs597/swift-package-manager that referenced this pull request May 4, 2021
* Fix --help printout

* What a fixed --help would look like

All of our subcommands need fixing. This is a demo of what fixing all the commands would look like

Also includes some fillings for `Options()` that didn't have any help

* Testable import, and throw InternalError

* Updated all remaining commands

* Bump Swift-Argument-Parser

Includes the new constructor that we need

* Reverted import of Commands

* Reverted indexStore, to be implemented in separate pr

Co-authored-by: Miguel Perez <[email protected]>
(cherry picked from commit a52d4d8)
miggs597 added a commit to miggs597/swift-package-manager that referenced this pull request May 5, 2021
* Fix --help printout

* What a fixed --help would look like

All of our subcommands need fixing. This is a demo of what fixing all the commands would look like

Also includes some fillings for `Options()` that didn't have any help

* Testable import, and throw InternalError

* Updated all remaining commands

* Bump Swift-Argument-Parser

Includes the new constructor that we need

* Reverted import of Commands

* Reverted indexStore, to be implemented in separate pr

Co-authored-by: Miguel Perez <[email protected]>
(cherry picked from commit a52d4d8)
neonichu pushed a commit that referenced this pull request Jul 8, 2021
* Fix --help printout

* What a fixed --help would look like

All of our subcommands need fixing. This is a demo of what fixing all the commands would look like

Also includes some fillings for `Options()` that didn't have any help

* Testable import, and throw InternalError

* Updated all remaining commands

* Bump Swift-Argument-Parser

Includes the new constructor that we need

* Reverted import of Commands

* Reverted indexStore, to be implemented in separate pr

Co-authored-by: Miguel Perez <[email protected]>
(cherry picked from commit a52d4d8)

Co-authored-by: tomer doron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants