-
Notifications
You must be signed in to change notification settings - Fork 56
Simplify argument parsing and processing in the plugin #88
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
620beb4
Add a simple utility for working with command line arguments
d-ronnqvist 83b8a8a
Use the new argument utility to parse arguments for each tool
d-ronnqvist b313f7b
Remove unused code
d-ronnqvist d77036f
Document all plugin flags in one place
d-ronnqvist ac5b152
Remove more unused code
d-ronnqvist 4feaf9d
Remove misleading code comment
d-ronnqvist e160165
Move definitions of documented option/flag names into DocumentedFlag
d-ronnqvist 4adbcb8
Remove incorrect default value (it differs by target kind)
d-ronnqvist 7978a92
Merge branch 'main' into argument-parsing
d-ronnqvist 0b3412e
Merge branch 'main' into argument-parsing
d-ronnqvist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
Sources/SwiftDocCPluginUtilities/Arguments+outputPath.swift
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
Sources/SwiftDocCPluginUtilities/Arguments+symbolGraphMinimumAccessLevel.swift
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
Sources/SwiftDocCPluginUtilities/CommandLineArguments/CommandLineArgument.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
|
||
/// A named command line argument; either a flag or an option with a value. | ||
public struct CommandLineArgument { | ||
/// The names of this command line argument. | ||
public var names: Names | ||
/// The kind of command line argument. | ||
public var kind: Kind | ||
|
||
/// A collection of names for a command line argument. | ||
public struct Names: Hashable { | ||
/// The preferred name for this command line argument. | ||
public var preferred: String | ||
/// All possible names for this command line argument. | ||
public var all: Set<String> | ||
|
||
/// Creates a new command line argument collection of names. | ||
/// | ||
/// - Parameters: | ||
/// - preferred: The preferred name for this command line argument. | ||
/// - alternatives: A collection of alternative names for this command line argument. | ||
public init(preferred: String, alternatives: Set<String> = []) { | ||
self.all = alternatives.union([preferred]) | ||
self.preferred = preferred | ||
} | ||
} | ||
|
||
/// A kind of command line argument. | ||
public enum Kind { | ||
/// A flag argument without an associated value. | ||
/// | ||
/// For example: `"--some-flag"`. | ||
case flag | ||
/// An option argument with an associated value. | ||
/// | ||
/// For example: `"--some-option", "value"` or `"--some-option=value"`. | ||
case option(value: String) | ||
} | ||
|
||
/// Creates a new command line flag with the given names. | ||
/// - Parameters: | ||
/// - names: The names for the new command line flag. | ||
public static func flag(_ names: Names) -> Self { | ||
.init(names: names, kind: .flag) | ||
} | ||
|
||
/// Creates a new command option with the given names and associated value. | ||
/// - Parameters: | ||
/// - names: The names for the new command line option. | ||
/// - value: The value that's associated with this command line option. | ||
public static func option(_ names: Names, value: String) -> Self { | ||
.init(names: names, kind: .option(value: value)) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.