-
Notifications
You must be signed in to change notification settings - Fork 53
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
Simplify argument parsing and processing in the plugin #88
Conversation
@swift-ci please test |
To make it easier to review this code, here are a handful of things that are worth calling out:
|
Plugins/SharedPackagePluginExtensions/PackageManager+getSymbolGraphsForDocC.swift
Show resolved
Hide resolved
@d-ronnqvist - Why are we implementing our own command line parser instead of using swift argument parser? |
Swift Argument Parses doesn't solve what the DocC Plugin needs to accomplish;
|
Sources/SwiftDocCPluginUtilities/CommandLineArguments/ParsedPluginArguments.swift
Outdated
Show resolved
Hide resolved
Sources/SwiftDocCPluginUtilities/CommandLineArguments/CommandLineArguments.swift
Outdated
Show resolved
Hide resolved
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.
Would it be possible to consolidate all the information about a given argument, i.e. name, spelling, value, default value, help text in one place?
For the flags with documentation I moved everything except the default value into the DocumentedFlag definition in f14201a. My reason for not moving the default values is that I find that it gets unnecessarily complicated doing so. There are mostly boolean flags but there are also a couple of non-boolean optional arguments (symbol-graph-access-level now and output-path in a follow up PR). I feel that this is an improvement that we can make in the future if we find a need for it then, but for now I prefer to keep the code simpler. |
@swift-ci please test |
6d39e64
to
4adbcb8
Compare
@swift-ci please test |
Sources/SwiftDocCPluginUtilities/CommandLineArguments/CommandLineArguments.swift
Show resolved
Hide resolved
) | ||
|
||
#if swift(>=5.9) | ||
private static let defaultExtendedTypesValue = true |
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.
This doesn't seem to extend to ParsedSymbolGraphArguments
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.
Correct. We don't apply any default values in ParsedSymbolGraphArguments
at all.
Instead, the symbol graph default values are populated in SwiftSourceModuleTarget/defaultSymbolGraphOptions(in:)
which duplicates this value here.
We could do all the Boolean values (so far) but the minimum access level depends on the target type, so we can't determine that default value from the arguments alone.
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.
I think that's OK for now, but we should be mindful about where we get the defaults from moving forward.
@@ -44,34 +44,33 @@ public enum HelpInformation { | |||
} | |||
|
|||
var supportedPluginFlags = [ |
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.
Could this be implemented as a (potentially abusive) conformance to CaseIterable
on DocumentedFlag
just trying to minimize the amount of things you need to do to introduce new flags.
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.
Not really since the help text has two lists ("plugin options" and "symbol graph options") but both their elements are defined as static members of DocumentedFlag
.
There's also one flag that depend on the supported features of the specific docc
executable, so this code would still need to make process the initial list of flags.
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.
LGTM!
@swift-ci please test |
@swift-ci please test macOS |
It looks like somewhere between
|
@swift-ci please test macOS |
I think this will be unblocked tomorrow when swiftlang/swift-package-manager#7903 is available in a development toolchain. If not, we may consider merging #90 while we wait. |
@swift-ci please test macOS |
@swift-ci please test |
Bug/issue #, if applicable:
Summary
This greatly simplifies the processing of command line arguments for the plugin itself, for what the plugin prepares for DocC, and for what there plugin prepares for symbol graph extraction.
Like #87, this PR is in preparation for another change. Whenever I've asked people about how they that I structure my PRs they've said that they prefer multiple smaller single-purpose PRs. I'm trying to do just that with this PR.
The purpose of this change is to prepare the code to make it easy to make a follow up PR that intercepts and customizes the
--output-dir
argument to allow using it when building documentation for more than one target. A secondary purpose of this change is to have a testable (and tested) foundation for parsing and processing the command line arguments in the plugin.This is very close to a non-functional change, but there are a few minor improvements:
--symbol-graph-minimum-access-level
option.--some-option=someValue
or correctly not parsing literal values after--
.Dependencies
None.
Testing
Nothing in particular. Run
bin/tests
.Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded[ ] Updated documentation if necessaryNot applicable.