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

Extract text package from gh #69

Merged
merged 2 commits into from Sep 13, 2022
Merged

Extract text package from gh #69

merged 2 commits into from Sep 13, 2022

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented Aug 25, 2022

This PR extracts the text package from gh. It also includes FuzzyAgo and FuzzyAgoAbbr from the utils package because they seemed to fit in well here.

cc cli/cli#5544

@samcoe samcoe self-assigned this Aug 25, 2022
@@ -207,43 +206,16 @@ func timeAgo(ago time.Duration) string {
return "just now"
Copy link
Contributor Author

@samcoe samcoe Aug 25, 2022

Choose a reason for hiding this comment

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

Kind of weird that we don't use FuzzyAgo instead of this entire function. Perhaps we should be? The current functionality was brought over from gh.

pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text_test.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

I feel pretty good about this extraction, only thing I am a bit concerned about is the clarity of the comments. Any feedback there is appreciated.

@samcoe samcoe marked this pull request as ready for review August 25, 2022 12:36
@samcoe samcoe requested review from mislav and vilmibm August 25, 2022 12:36
Copy link

@AmEarth AmEarth left a comment

Choose a reason for hiding this comment

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

text-package

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I would vote to remove most of the functions there and focus on just the handful of ones that we want to control the implementation of, such as ANSI-codes aware implementations of measuring display width, truncation, and indentation.

Unlike in Ruby or JavaScript, offering a grab-bag of tiny utilities as a Go library isn't what most Go developers want. In fact, if they need some of these utilities in their own programs, most Go developers might choose to just inline them there instead of adding a dependency. Of course, gh extension authors will already depend on the go-gh repository anyway, but at least we can reduce the surface of the APIs we offer.

pkg/text/text.go Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
}

// Pluralize returns a concatenated string with num and the plural form of thing if necessary.
func Pluralize(num int, thing string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that such simplistic pluralization implementation should best be inlined in people's extensions (if needed at all) instead of being exposed from go-gh

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 agree that it is simplistic, but it is necessary for FuzzyAgo and also used independently of that in gh so if it isn't exposed here then it will need to be duplicated in gh. Going to leave it in for now.

pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
pkg/text/text.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@samcoe samcoe left a comment

Choose a reason for hiding this comment

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

@mislav Thanks for the review. I made the requested changes if you wouldn't mind giving it another look 🙇

}

// Pluralize returns a concatenated string with num and the plural form of thing if necessary.
func Pluralize(num int, thing string) string {
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 agree that it is simplistic, but it is necessary for FuzzyAgo and also used independently of that in gh so if it isn't exposed here then it will need to be duplicated in gh. Going to leave it in for now.

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thank you! 🚀

@samcoe samcoe merged commit 0401986 into trunk Sep 13, 2022
@samcoe samcoe deleted the text-package branch September 13, 2022 12:51
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