From ae161cccf91851e4b6ec50ec757c9efa323822e7 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Wed, 16 Aug 2023 00:54:05 +0700 Subject: [PATCH] feat: round star count to k --- go.mod | 1 + go.sum | 6 ++++++ internal/cli/action_overlook.go | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 421f6d2..7bd2a9b 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/make-go-great/color-go v0.5.0 github.com/make-go-great/netrc-go v0.0.2 github.com/sourcegraph/conc v0.3.0 + github.com/spf13/cast v1.5.1 github.com/urfave/cli/v2 v2.25.7 golang.org/x/oauth2 v0.8.0 ) diff --git a/go.sum b/go.sum index 6625a82..c197497 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= @@ -22,6 +23,8 @@ github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/ github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/make-go-great/color-go v0.5.0 h1:iCSIBybwoo+ctK3QdSWPJPAl05/a3tBrxvOURZRT1qA= github.com/make-go-great/color-go v0.5.0/go.mod h1:GoWscSdNNxjxsQdQCgGlUoADdRHqjmuBMsdr+Rb/QQM= github.com/make-go-great/netrc-go v0.0.2 h1:+slj+cMcNL+W/xbHvLPJ8DyTrjcfzQt7bYWZtNV+Isg= @@ -33,10 +36,13 @@ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPn github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= diff --git a/internal/cli/action_overlook.go b/internal/cli/action_overlook.go index 4d45a46..288e348 100644 --- a/internal/cli/action_overlook.go +++ b/internal/cli/action_overlook.go @@ -12,6 +12,7 @@ import ( "github.com/google/go-github/v53/github" "github.com/sourcegraph/conc/pool" + "github.com/spf13/cast" "github.com/urfave/cli/v2" ) @@ -126,9 +127,19 @@ func (a *action) Overlook(c *cli.Context) error { // Print w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) for _, r := range listGHRepoData { - fmt.Fprintf(w, "Module %s\t%d\t⭐\tLast commit %s\n", r.Name, r.StarCount, r.LastCommitAt.Format(time.DateOnly)) + fmt.Fprintf(w, "Module %s\t%s\t⭐\tLast commit %s\n", r.Name, roundK(r.StarCount), r.LastCommitAt.Format(time.DateOnly)) } w.Flush() return nil } + +// Nearest thounsand +// 1234 -> 1K +func roundK(v int) string { + if v < 1000 { + return cast.ToString(v) + } + + return fmt.Sprintf("%dK", v/1000) +}