-
Notifications
You must be signed in to change notification settings - Fork 344
Introduce subcommand grouping into the command configuration to improve help #644
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
6 commits
Select commit
Hold shift + click to select a range
b013355
Introduce subcommand grouping into the command configuration to impro…
DougGregor ab563a2
Add an optional abstract to command groups
DougGregor 03cd075
Expand subcommand group result builders to handle all result-builder …
DougGregor e51daba
Revert "Add an optional abstract to command groups"
DougGregor 56283d4
Eliminate result builders in favor of a second "groupedSubcommands" a…
DougGregor 6c2ab1a
Drop the (ungrouped) "subcommands" heading when there are none.
DougGregor 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,27 @@ public struct CommandConfiguration: Sendable { | |
public var shouldDisplay: Bool | ||
|
||
/// An array of the types that define subcommands for this command. | ||
public var subcommands: [ParsableCommand.Type] | ||
|
||
/// | ||
/// This property "flattens" the grouping structure of the subcommands. | ||
/// Use 'ungroupedSubcommands' to access 'groupedSubcommands' to retain the grouping structure. | ||
public var subcommands: [ParsableCommand.Type] { | ||
get { | ||
return ungroupedSubcommands + groupedSubcommands.flatMap { $0.subcommands } | ||
} | ||
|
||
set { | ||
groupedSubcommands = [] | ||
ungroupedSubcommands = newValue | ||
} | ||
} | ||
|
||
/// An array of types that define subcommands for this command and are | ||
/// not part of any command group. | ||
public var ungroupedSubcommands: [ParsableCommand.Type] | ||
|
||
/// The list of subcommands and subcommand groups. | ||
public var groupedSubcommands: [CommandGroup] | ||
Comment on lines
+64
to
+69
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. These look great 👍🏻 |
||
|
||
/// The default command type to run if no subcommand is given. | ||
public var defaultSubcommand: ParsableCommand.Type? | ||
|
||
|
@@ -79,8 +98,10 @@ public struct CommandConfiguration: Sendable { | |
/// a `--version` flag. | ||
/// - shouldDisplay: A Boolean value indicating whether the command | ||
/// should be shown in the extended help display. | ||
/// - subcommands: An array of the types that define subcommands for the | ||
/// command. | ||
/// - ungroupedSubcommands: An array of the types that define subcommands | ||
/// for the command that are not part of any command group. | ||
/// - groupedSubcommands: An array of command groups, each of which defines | ||
/// subcommands that are part of that logical group. | ||
/// - defaultSubcommand: The default command type to run if no subcommand | ||
/// is given. | ||
/// - helpNames: The flag names to use for requesting help, when combined | ||
|
@@ -97,7 +118,8 @@ public struct CommandConfiguration: Sendable { | |
discussion: String = "", | ||
version: String = "", | ||
shouldDisplay: Bool = true, | ||
subcommands: [ParsableCommand.Type] = [], | ||
subcommands ungroupedSubcommands: [ParsableCommand.Type] = [], | ||
groupedSubcommands: [CommandGroup] = [], | ||
defaultSubcommand: ParsableCommand.Type? = nil, | ||
helpNames: NameSpecification? = nil, | ||
aliases: [String] = [] | ||
|
@@ -108,7 +130,8 @@ public struct CommandConfiguration: Sendable { | |
self.discussion = discussion | ||
self.version = version | ||
self.shouldDisplay = shouldDisplay | ||
self.subcommands = subcommands | ||
self.ungroupedSubcommands = ungroupedSubcommands | ||
self.groupedSubcommands = groupedSubcommands | ||
self.defaultSubcommand = defaultSubcommand | ||
self.helpNames = helpNames | ||
self.aliases = aliases | ||
|
@@ -124,7 +147,8 @@ public struct CommandConfiguration: Sendable { | |
discussion: String = "", | ||
version: String = "", | ||
shouldDisplay: Bool = true, | ||
subcommands: [ParsableCommand.Type] = [], | ||
subcommands ungroupedSubcommands: [ParsableCommand.Type] = [], | ||
groupedSubcommands: [CommandGroup] = [], | ||
defaultSubcommand: ParsableCommand.Type? = nil, | ||
helpNames: NameSpecification? = nil, | ||
aliases: [String] = [] | ||
|
@@ -136,7 +160,8 @@ public struct CommandConfiguration: Sendable { | |
self.discussion = discussion | ||
self.version = version | ||
self.shouldDisplay = shouldDisplay | ||
self.subcommands = subcommands | ||
self.ungroupedSubcommands = ungroupedSubcommands | ||
self.groupedSubcommands = groupedSubcommands | ||
self.defaultSubcommand = defaultSubcommand | ||
self.helpNames = helpNames | ||
self.aliases = aliases | ||
|
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,28 @@ | ||
//===----------------------------------------------------------*- swift -*-===// | ||
// | ||
// This source file is part of the Swift Argument Parser open source project | ||
// | ||
// Copyright (c) 2020 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
/// A set of commands grouped together under a common name. | ||
public struct CommandGroup: Sendable { | ||
/// The name of the command group that will be displayed in help. | ||
public let name: String | ||
|
||
/// The list of subcommands that are part of this group. | ||
public let subcommands: [ParsableCommand.Type] | ||
|
||
/// Create a command group. | ||
public init( | ||
name: String, | ||
subcommands: [ParsableCommand.Type] | ||
) { | ||
self.name = name | ||
self.subcommands = subcommands | ||
} | ||
} |
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
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.
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.
Can we drop this stray doc comment line?
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 was using the extra line to separate the "abstract" line from the "detail" line.
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.
Wow I can't this morning, I made like 2 other mistakes similar, sorry about the noise
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.
It's a weird diff!