Skip to content

Commit e394bf3

Browse files
committed
Revert "ArgumentHelp.Visibility levels API (#390)"
This reverts commit 4cdcc17.
1 parent 5772794 commit e394bf3

File tree

4 files changed

+7
-73
lines changed

4 files changed

+7
-73
lines changed

Sources/ArgumentParser/Documentation.docc/Articles/CustomizingHelp.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ OPTIONS:
185185

186186
## Hiding Arguments and Commands
187187

188-
You may want to suppress features under development or experimental flags from the generated help screen. You can hide an argument or a subcommand by passing `visibility: .hidden` to the property wrapper or `CommandConfiguration` initializers, respectively.
188+
You may want to suppress features under development or experimental flags from the generated help screen. You can hide an argument or a subcommand by passing `shouldDisplay: false` to the property wrapper or `CommandConfiguration` initializers, respectively.
189189

190190
`ArgumentHelp` includes a `.hidden` static property that makes it even simpler to hide arguments:
191191

Sources/ArgumentParser/Parsable Properties/ArgumentHelp.swift

+5-48
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@
1111

1212
/// Help information for a command-line argument.
1313
public struct ArgumentHelp {
14-
/// Visibility level of an argument's help.
15-
public enum Visibility {
16-
/// Show help for this argument whenever appropriate.
17-
case `default`
18-
19-
/// Only show help for this argument in the extended help screen.
20-
case hidden
21-
22-
/// Never show help for this argument.
23-
case `private`
24-
}
25-
2614
/// A short description of the argument.
2715
public var abstract: String = ""
2816

@@ -36,57 +24,26 @@ public struct ArgumentHelp {
3624
/// flags don't include a value.
3725
public var valueName: String?
3826

39-
/// A visibility level indicating whether this argument should be shown in
40-
/// the extended help display.
41-
public var visibility: Visibility = .default
42-
4327
/// A Boolean value indicating whether this argument should be shown in
4428
/// the extended help display.
45-
@available(*, deprecated, message: "Use visibility level instead.")
46-
public var shouldDisplay: Bool {
47-
get {
48-
return visibility == .default
49-
}
50-
set {
51-
visibility = newValue ? .default : .hidden
52-
}
53-
}
29+
public var shouldDisplay: Bool = true
5430

5531
/// Creates a new help instance.
56-
@available(*, deprecated, message: "Use init(_:discussion:valueName:visibility:) instead.")
5732
public init(
5833
_ abstract: String = "",
5934
discussion: String = "",
6035
valueName: String? = nil,
61-
shouldDisplay: Bool)
36+
shouldDisplay: Bool = true)
6237
{
6338
self.abstract = abstract
6439
self.discussion = discussion
6540
self.valueName = valueName
6641
self.shouldDisplay = shouldDisplay
6742
}
68-
69-
/// Creates a new help instance.
70-
public init(
71-
_ abstract: String = "",
72-
discussion: String = "",
73-
valueName: String? = nil,
74-
visibility: Visibility = .default)
75-
{
76-
self.abstract = abstract
77-
self.discussion = discussion
78-
self.valueName = valueName
79-
self.visibility = visibility
80-
}
81-
82-
/// A `Help` instance that shows an argument only in the extended help display.
83-
public static var hidden: ArgumentHelp {
84-
ArgumentHelp(visibility: .hidden)
85-
}
86-
43+
8744
/// A `Help` instance that hides an argument from the extended help display.
88-
public static var `private`: ArgumentHelp {
89-
ArgumentHelp(visibility: .private)
45+
public static var hidden: ArgumentHelp {
46+
ArgumentHelp(shouldDisplay: false)
9047
}
9148
}
9249

Sources/ArgumentParser/Parsing/ArgumentDefinition.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct ArgumentDefinition {
7979
self.abstract = help?.abstract ?? ""
8080
self.discussion = help?.discussion ?? ""
8181
self.valueName = help?.valueName ?? ""
82-
self.shouldDisplay = (help?.visibility ?? .default) == .default
82+
self.shouldDisplay = help?.shouldDisplay ?? true
8383
}
8484
}
8585

Tests/ArgumentParserUnitTests/HelpGenerationTests.swift

-23
Original file line numberDiff line numberDiff line change
@@ -547,29 +547,6 @@ extension HelpGenerationTests {
547547
XCTAssertEqual(AllValues.SpecializedSynthesized.allValueStrings, opts[4].help.allValues)
548548
XCTAssertEqual(AllValues.SpecializedSynthesized.allValueStrings, opts[5].help.allValues)
549549
}
550-
551-
struct Q: ParsableArguments {
552-
@Option(help: "Your name") var name: String
553-
@Option(help: "Your title") var title: String?
554-
555-
@Argument(help: .private) var privateName: String?
556-
@Option(help: .private) var privateTitle: String?
557-
@Flag(help: .private) var privateFlag: Bool = false
558-
@Flag(inversion: .prefixedNo, help: .private) var privateInvertedFlag: Bool = true
559-
}
560-
561-
func testHelpWithPrivate() {
562-
// For now, hidden and private have the same behaviour
563-
AssertHelp(for: Q.self, equals: """
564-
USAGE: q --name <name> [--title <title>]
565-
566-
OPTIONS:
567-
--name <name> Your name
568-
--title <title> Your title
569-
-h, --help Show help information.
570-
571-
""")
572-
}
573550
}
574551

575552
// MARK: - Issue #278 https://github.com/apple/swift-argument-parser/issues/278

0 commit comments

Comments
 (0)