Skip to content

Commit

Permalink
Revert "ArgumentHelp.Visibility levels API (#390)"
Browse files Browse the repository at this point in the history
This reverts commit 4cdcc17.
  • Loading branch information
natecook1000 committed Feb 1, 2022
1 parent 5772794 commit e394bf3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ OPTIONS:

## Hiding Arguments and Commands

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

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

Expand Down
53 changes: 5 additions & 48 deletions Sources/ArgumentParser/Parsable Properties/ArgumentHelp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@

/// Help information for a command-line argument.
public struct ArgumentHelp {
/// Visibility level of an argument's help.
public enum Visibility {
/// Show help for this argument whenever appropriate.
case `default`

/// Only show help for this argument in the extended help screen.
case hidden

/// Never show help for this argument.
case `private`
}

/// A short description of the argument.
public var abstract: String = ""

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

/// A visibility level indicating whether this argument should be shown in
/// the extended help display.
public var visibility: Visibility = .default

/// A Boolean value indicating whether this argument should be shown in
/// the extended help display.
@available(*, deprecated, message: "Use visibility level instead.")
public var shouldDisplay: Bool {
get {
return visibility == .default
}
set {
visibility = newValue ? .default : .hidden
}
}
public var shouldDisplay: Bool = true

/// Creates a new help instance.
@available(*, deprecated, message: "Use init(_:discussion:valueName:visibility:) instead.")
public init(
_ abstract: String = "",
discussion: String = "",
valueName: String? = nil,
shouldDisplay: Bool)
shouldDisplay: Bool = true)
{
self.abstract = abstract
self.discussion = discussion
self.valueName = valueName
self.shouldDisplay = shouldDisplay
}

/// Creates a new help instance.
public init(
_ abstract: String = "",
discussion: String = "",
valueName: String? = nil,
visibility: Visibility = .default)
{
self.abstract = abstract
self.discussion = discussion
self.valueName = valueName
self.visibility = visibility
}

/// A `Help` instance that shows an argument only in the extended help display.
public static var hidden: ArgumentHelp {
ArgumentHelp(visibility: .hidden)
}


/// A `Help` instance that hides an argument from the extended help display.
public static var `private`: ArgumentHelp {
ArgumentHelp(visibility: .private)
public static var hidden: ArgumentHelp {
ArgumentHelp(shouldDisplay: false)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/ArgumentParser/Parsing/ArgumentDefinition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct ArgumentDefinition {
self.abstract = help?.abstract ?? ""
self.discussion = help?.discussion ?? ""
self.valueName = help?.valueName ?? ""
self.shouldDisplay = (help?.visibility ?? .default) == .default
self.shouldDisplay = help?.shouldDisplay ?? true
}
}

Expand Down
23 changes: 0 additions & 23 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -547,29 +547,6 @@ extension HelpGenerationTests {
XCTAssertEqual(AllValues.SpecializedSynthesized.allValueStrings, opts[4].help.allValues)
XCTAssertEqual(AllValues.SpecializedSynthesized.allValueStrings, opts[5].help.allValues)
}

struct Q: ParsableArguments {
@Option(help: "Your name") var name: String
@Option(help: "Your title") var title: String?

@Argument(help: .private) var privateName: String?
@Option(help: .private) var privateTitle: String?
@Flag(help: .private) var privateFlag: Bool = false
@Flag(inversion: .prefixedNo, help: .private) var privateInvertedFlag: Bool = true
}

func testHelpWithPrivate() {
// For now, hidden and private have the same behaviour
AssertHelp(for: Q.self, equals: """
USAGE: q --name <name> [--title <title>]
OPTIONS:
--name <name> Your name
--title <title> Your title
-h, --help Show help information.
""")
}
}

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

0 comments on commit e394bf3

Please sign in to comment.