Skip to content

ArgumentHelp.Visibility levels API #390

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

Conversation

McNight
Copy link
Contributor

@McNight McNight commented Jan 13, 2022

This pull request (as a draft for now) adds a new ArgumentHelp.Visibility API with multiple levels allowing to indicate whether help messages should be shown in the extended help display.
It follows suggestions made by @natecook1000 in issue #384.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

@McNight
Copy link
Contributor Author

McNight commented Jan 13, 2022

Some comments:

  • hidden and private have the same properties for now to make sure all tests are still passing
  • I added a test in HelpGenerationTests.swift near the bottom of the file, I don't know if it should be regrouped with the testHelpWithHidden() test
  • I explicitly made several commits but I could squash them if needed

/// the extended help display.
public var shouldDisplay: Bool = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we can eliminate this property since it is part of our public API, but it can be deprecated and forward get/set to the new visibility property you've defined

Same for the initializer below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, my bad

@McNight McNight force-pushed the mcnight/argumenthelp_visibility_levels branch from 2c6eaec to e2707e0 Compare January 15, 2022 13:57
@McNight
Copy link
Contributor Author

McNight commented Jan 15, 2022

I made the modifications to keep and mark the shouldDisplay boolean property as deprecated. I wanted to do the same for the other initializer but I had some trouble to mark it as public or even internal since it conflicts with the other one.

@McNight McNight requested a review from rauhul January 15, 2022 14:02
set {
visibility = newValue ? .default : .hidden
}
}

/// Creates a new help instance.
public init(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a depreciation to this initializer start moving away from shouldDisplay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I marked this initializer as deprecated but didn't provide a deprecation message since I don't any a public alternative for now. However, I just learned (from you :)) about @_disfavoredOverload, do you think it could be useful here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message should guide users to ArgumentHelp.init(_:discussion:valueName: visibility:). @_disfavoredOverload probably is needed as well since both inits can be called without providing any arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A message pointing at the new initializer would be great! If you remove the default value for shouldDisplay, you won't need to use @_disfavoredOverload.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clever solution!

@McNight McNight force-pushed the mcnight/argumenthelp_visibility_levels branch from e2707e0 to f245342 Compare January 18, 2022 00:35
Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, @McNight! Don't worry about squashing commits, we do that when merging.

set {
visibility = newValue ? .default : .hidden
}
}

/// Creates a new help instance.
public init(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A message pointing at the new initializer would be great! If you remove the default value for shouldDisplay, you won't need to use @_disfavoredOverload.

@@ -11,6 +11,17 @@

/// Help information for a command-line argument.
public struct ArgumentHelp {
public enum Visibility {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add an abstract for this type, as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure !

@McNight McNight force-pushed the mcnight/argumenthelp_visibility_levels branch from f245342 to 6357b67 Compare January 19, 2022 22:01
Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good! 👍🏻

@McNight McNight marked this pull request as ready for review January 21, 2022 00:01
@natecook1000
Copy link
Member

@swift-ci Please test

@natecook1000 natecook1000 merged commit 4cdcc17 into apple:main Jan 21, 2022
natecook1000 added a commit that referenced this pull request Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants