Skip to content

Conversation

@natecook1000
Copy link
Member

@natecook1000 natecook1000 commented Mar 13, 2020

Description

This provides a method on all ParsableArguments/ParsableCommand types that lets you retrieve the exit code associated with an error.

Detailed Design

  1. Add an exitCode(for:) method that converts an error to an ExitCode instance.
extension ParsableArguments {
  /// Returns the exit code for the given error.
  ///
  /// - Parameter error: An error to generate a message for.
  /// - Returns: The exit code for the `error`.
  public static func exitCode(for error: Error) -> ExitCode
}
  1. Upgrade the ExitCode type to be a bit more useful, making it RawRepresentable and Hashable. The represented code is now available through the rawValue property.

Documentation Plan

I included symbol documentation for the new APIs.

Test Plan

I added unit tests for the exitCode(for) method and converted the integration test helper to use ExitCodes instead of plain Int32s.

Source Impact

No source impact or deprecations.

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

command: String,
expected: String? = nil,
exitCode: Int32 = 0,
exitCode: Int32 = ExitCode.success.rawValue,
Copy link
Contributor

@miguelangel-dev miguelangel-dev Mar 18, 2020

Choose a reason for hiding this comment

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

I think you should use directly ExitCode as a type for AssertExecuteCommand - to force you to keep tests with the same semantic and if it is the fail-output for the execution, the type should be always the same.

If you use Int32 you will be less strict, and some bugs can be introduced. wdut?

Suggested change
exitCode: Int32 = ExitCode.success.rawValue,
exitCode: ExitCode = .success,

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 I was resisting this for some reason. Thanks!

@natecook1000 natecook1000 marked this pull request as ready for review March 21, 2020 17:44
@natecook1000 natecook1000 merged commit ddc828f into master Mar 21, 2020
@natecook1000 natecook1000 deleted the nate/exitcode_method branch March 21, 2020 17:44
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