Skip to content
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

Argument Parser migration #14

Merged

Conversation

elfenlaid
Copy link
Contributor

A first drafts for arguments parser adoption. The meat is somewhere between the first fifty lines of Badgy.swift.

Though, it's a far from done. Just sharing an initial draft and thoughts around it.

@elfenlaid elfenlaid changed the base branch from master to rc-argument-parser June 21, 2020 05:42
@elfenlaid
Copy link
Contributor Author

Whoa, it's a complete mess by now +654 −301 🙈

I've tried to keep the core logic intact as much as possible. Though, there are few minor differences in the error reporting.

Now both CLIs are functional with a given priority to SwiftCLI. ArgumentParser-based one is shielded behind preprocessor macros. To run it use:

swift run -Xswiftc -DARGUMENT_PARSER badgy

@arthurpalves would you mind to have a quick glance and decide whether the changes should be served in a more atomic way?

@elfenlaid elfenlaid changed the title Drafting arguments parser adoption Argument Parser migration Jun 21, 2020
@elfenlaid elfenlaid marked this pull request as ready for review June 21, 2020 10:56
Copy link

@KyLeggiero KyLeggiero left a comment

Choose a reason for hiding this comment

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

So glad this was done! I'm taking notes for my own projects 😄

Package.swift Show resolved Hide resolved
Sources/Badgy/Commands/Badgy.swift Outdated Show resolved Hide resolved
Sources/Badgy/Commands/Badgy.swift Outdated Show resolved Hide resolved
@OptionGroup()
var options: Badgy.Options

@Option(help: "Rotation angle of the badge")

Choose a reason for hiding this comment

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

In Degrees? Radians? Percent of a full rotation? What's the default if it's not specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're totally right.
I wonder whether the same should be done to color and tintColor 🤔

Sources/Badgy/Commands/Badgy.swift Outdated Show resolved Hide resolved
Sources/Badgy/Helpers/ColorCode+Hex.swift Outdated Show resolved Hide resolved
Sources/Badgy/Helpers/ColorCode+Name.swift Show resolved Hide resolved
Sources/Badgy/Helpers/ColorCode+Name.swift Show resolved Hide resolved
Sources/Badgy/Helpers/Icon.swift Outdated Show resolved Hide resolved
Sources/Badgy/main.swift Show resolved Hide resolved
@elfenlaid
Copy link
Contributor Author

So glad this was done! I'm taking notes for my own projects 😄

Thank you so much for the thorough review! :)

@arthurpalves
Copy link
Owner

What a party! 💯
You guys have been busy. Nice one!

Copy link
Owner

@arthurpalves arthurpalves left a comment

Choose a reason for hiding this comment

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

Upon merge into rc-argument-parser we can initiate next step to remove support for SwiftCLI

Package.swift Show resolved Hide resolved
Sources/Badgy/Commands/Badgy.swift Show resolved Hide resolved
@Option(default: .bottom, help: "Position on which to place the badge. Supported positions: \(Position.longLabelPositions.formatted())")
var position: Position

@Option(default: 0, help: "The rotation angle of the badge in degrees range of -180 ... 180")
Copy link
Owner

Choose a reason for hiding this comment

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

Does it behave any different with negative values than SwiftCLI?
I've recently seen an issue with it for not really testing before.
Only acceptable when escaped and within single or double quotes

--angle '\-15'

Copy link
Owner

Choose a reason for hiding this comment

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

Out of scope for this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, good catch, haven't thought about it before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a common problem for CLIs :)
Yet, as a workaround: ArgumentParser handles negative values if = is used. Example: --angle=-15

Related:
apple/swift-argument-parser#31
apple/swift-argument-parser#153

@arthurpalves arthurpalves merged commit c89b0f1 into arthurpalves:rc-argument-parser Jun 26, 2020
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.

None yet

3 participants